ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
ASP Dot Net Tutorial - Index
ASP Dot Net Tutorial - Microsofts ASP.NET
ASP Dot Net Tutorial - Begining Web Forms
ASP Dot Net Tutorial - User Controls
ASP Dot Net Tutorial - ADO .NET
ASP Dot Net Tutorial - DataBinding to WebControls
ASP Dot Net Tutorial - DataList Controls
ASP Dot Net Tutorial - DataGrid Control
ASP Dot Net Tutorial - Advance Practical Examples on DataGrid
ASP Dot Net Tutorial - Working with DataSets
ASP Dot Net Tutorial - Working with XML
ASP Dot Net Tutorial - Forms Based Authentication
ASP Dot Net Tutorial - Windows Based Authentication

Online Personal Trainer Certification
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Makeup Artist Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses


  Home > Courses, Tutorials & eBooks > ASP.NET Tutorial > The DataList Controls

ASP.NET Tutorial - The DataList Controls

                                                                                                                 Page 2 of 3


To specify the appearance of items in a template, the style of Template’s can be set. For example, you might specify that:

  • Items are rendered with black text on a white background
  • Alternating items are rendered with black text on a light gray background
  • The selected item is rendered with bold black text on a yellow background
  • Items being edited are rendered with black text on a light blue background

Each template supports its own style object whose properties can be set both at the time of design and at the time of the run.

When an item is selected in a DataList, the SelectedItem template is displayed, and when it is selected for editing in a DataList, the EditItem template is displayed.

The DataGrid control, supports the following four templates when a column is displayed using a TemplateColumn:


Controls how the header of the DataGrid is formatted


Controls the formatting of items displayed by the DataGrid


Controls how the footer of the DataGrid is formatted

Edit ItemTemplate

Controls how an item selected for editing is formatted

The Edit ItemTemplate is displayed when you select an item for editing in a DataGrid.

Using the Datakeys Collection

 DataKeys collection is used to access the key values of each record (displayed as a row) in a data listing control. This allows storing the key field with a data listing control without displaying it in the control. This collection is automatically filled with the values from the field specified by the DataKeyField property.

The key field is commonly used in a handler for an event, such as ItemCommand or DeleteCommand, as part of an update query string, to revise a specific record in the data source. The key field helps to update the query string identifying the appropriate record to modify.

Both the DataList and DataGrid controls have a special collection named DataKeys. This collection represents the primary key field associated with each item in the control.

For example, imagine that you have a database table named Employees and the Employees table further has an identity column named EmployeeID which you want to display and edit with a DataGrid control.

You can associate the value of the identity column with each item in the DataGrid by assigning the name of the identity column to the DataKeyField property of the DataGrid like this:




Runat="Server" />


The advantage of associating the identity column with each item in the DataGrid is that the value of the column can be retrieved whenever a field is edited in the DataGrid.

If a field in the DataGrid is updated and further requires the corresponding field to be updated in the under­lying database table, the DataKeys collection can be used to uniquely identify the correct row in the database table for the update.

DataList Control

The DataList Web server control displays rows of database information in customized format. The displayed data in customized format is defined in the item, alternating item, selected item, and edit item templates. Header, footer, and separator templates are also available to customize the overall appearance of the DataList. By including Button Web server controls in the template, list items can be connected to the code that allows users to switch between display, selection, and editing modes.

The following sections, will show the use of DataList control, to format and display data from a database table, to create multicolumn menus and to use the DataList to edit data in a database table.

Displaying Data In a DataList

 A DataList can be used like a Repeater control-to display records from a database table. However, unlike a Repeater control, a default behavior of DataList controls default is to show the database records within an HTML table.

Look at the following example: -


The output of above example is show below: -

In the above example each row from the Employees table is displayed in a separate HTML table row ,when the DataList displays the records.



Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
© ExpertRating 2015. All Rights Reserved.