VisualBuilder
  Home > Aspnet > Tutorials > DataList - ASP.NET Tutorial
Tell a friend
Link to us
Total Members
      Members: 84661
     
Sitemap Forum Chat
Home
ASP.NET Tutorial Home
1 . Introduction
2 . Static and Dynamic Web sites
3 . Dynamic Web sites
4 . What is ASP
5 . How ASP Works
6 . What is ASP.NET
7 . What is a Framework?
8 . ASP.NET Versions
9 . The .NET Framework architecture
10 . Important Terminologies
11 . Why Use ASP.NET
12 . Setting up ASP.NET
13 . Installation of .NET Framework 2.0
14 . Installing the Software Development Kit (SDK)
15 . Configuring IIS for ASP.NET 2.0
16 . Developing your First ASP.NET Page
17 . Understanding the ASP.NET Code
18 . Next Steps
19 . Asp.Net
20 . DataList
21 . Validation Controls
22 . ExecuteNonQuery
23 . ADO.NET
24 . Using Parameters with Queries
25 . EXECUTE SCALER: Retrieving Single Database Record
26 . Improving Database Performance Using Stored Procedure
27 . Example for XML Handling Using ASP. Net.
28 . CACHING IN ASP.NET APPLICATION
29 . GridView Control
30 . Master-Detail Relationship: Using DATALIST and REPEATER Control
31 . Data Binding – WebControls [REPEATER CONTROL]
32 . Session Management in Asp.Net
 
Aspnet Group Home
Aspnet Discussion (10)
Aspnet Members (2382)
Aspnet Resources
Aspnet Source Code (388)
Aspnet Articles (1)
Aspnet Blogs
Aspnet Jobs
Aspnet Components (201)
Aspnet Books
Aspnet Websites (21)
Aspnet News (105)
Aspnet Q & A (114)
- Aspnet Ask Question
- Aspnet Questions
- Aspnet Unanswered Questions
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (434 )
Source Code (3275 )
Articles (11 )
Components (1595 )
News (888 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise

Aspnet Tutorial
 DataList
  << Prev: Asp.Net Next: Validation Controls >>

DataList is the feature-rich control included in the Asp.Net framework. They include the concept of Event Bubbling, Template that will manipulate the display of data and the Data Keys collection.


 


Event Bubbling:


 


The event bubbling concept provided by DataList, DataGrid and Repeater Control will help you to capture the events in their child control. When an event is raised in a child control, the event “bubbles up” to the containing control, and the containing control can then execute a subroutine to handle the event.


 


Main events in DataList:


 


The following five are the main events in the Datalist.



  1. ItemCommand: Raised by a child control when an event is not handled by CancelCommand, Delete Command, EditCommand or Update Command.

  2. UpdateCommand: capture event raised by child control with CommandName=”update

  3. EditCommand: capture event raised by child control with CommandName=”edit

  4. DeleteCommand: capture event raised by child control with CommandName=”delete

  5. CancelCommand: capture event raised by child control with CommandName=”cancel


Templates that are used to format the output of the control.


 


We can format the output in the ASP.net by using the pre defined templates. The following seven templates will be used to format the output.



  1. HeaderTemplate: format the header for DataList

  2. ItemTemplate: format each item in the DataList

  3. AlternatingItemTemplate: control the formatting for alternate item.

  4. SeparatorTemplate: Display a separator b/w each item displayed.

  5. FooterTemplate: format footer.

  6. SelectedItemTemplate: control how selected item is formatted.

  7. EditItemTemplate: control how an item selected for editing is formatted.


 


RepeatColumns and RepeatDirection


 


The column layout of the datalist can be controlled using the RepeatColumns and RepeatDirection property. The RepeatColumns property determines the number of columns to be displayed whereas the RepeatDirection determines whether columns should be repeated horizontally or vertically. By default its value is vertical.


 


Example:-


Note: -This example will fetch the records from database and displayed the records in datalist control. In the example we display the first name and last name of the Employee.


 


DataListContro.aspx


 


<% @ Page Language ="VB" AutoEventWireup ="false" CodeFile ="Example12.aspx.vb" Inherits ="Example12" %>


 


<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


 


< html xmlns ="http://www.w3.org/1999/xhtml" >


< head runat ="server">


</ head >


< body >


< form id ="form1" runat ="server">


< div >


< asp : DataList ID ="DataList1" runat ="server" RepeatColumns ="2" RepeatDirection ="Horizontal" Width ="192px">


< ItemTemplate >


<% # Container.DataItem( "fname" ) %>


< br >


<% # Container.DataItem( "lname" ) %>


</ ItemTemplate >


< SelectedItemTemplate >< b >< i >


<% # Container.DataItem( "fname" ) %>


< br >


<% # Container.DataItem( "lname" ) %> </ i ></ b >


</ SelectedItemTemplate >


</ asp : DataList ></ div >


</ form >


</ body >


</ html >


 


 


DataListControl.aspx.vb


 


Imports System


Imports System.Data


Imports System.Data.SqlClient


 


 


Partial Class Example12 Inherits System.Web.UI.Page


 


Protected Sub Page_Load( ByVal sender As Object , ByVal e As System.EventArgs) Handles Me .Load


Dim con As SqlConnection


Dim ada As SqlDataAdapter


Dim dst As DataSet


 


con = New SqlConnection( "Data Source=localhost;Initial catalog=pubs;UID=sa;pwd=sa" )


ada = New SqlDataAdapter( "select * from Employee" , con)


dst = New DataSet


con.Open()


ada.Fill(dst, "Employee" )


con.Close()


DataList1.DataSource = dst.Tables( "Employee" )


DataList1.DataBind()


End Sub


End Class


  << Prev: Asp.Net Next: Validation Controls >>
Aspnet Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
LINKS
MSN
Video Surveillance
Exchange Hosting

 
ADVERTISEMENT
Partner List
Code Project
ASP Alliance
More
 
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising