The DataList control is a data bound list control that displays items using templates. The DataList control supports selecting and editing of data. The contents of the DataList control can be manipulated by using templates. It acts as a container of repeated data items. DataList and GridView Web controls can contain child controls that raise events. Therefore, a DataList control may have a child control as part of a template that raises an event. The child control event is "bubbled up” (sent up) to the control's container. The container control raises an event called RowCommand with parameter values. These values allow one to determine which control raised the original event. One is then able to respond to this event. Alternatively, one can write individual event handlers for the child controls.
• Using the DataSourceID property, binding to data source controls, such as SqlDataSource, ObjectDataSource, and XmlDataSource, is supported
• Using the DataSource property, binding to an object that implements the System.Collections.IEnumerable interface is supported
• DataList supports selecting and editing. Typically, the Repeater is mostly used for displaying data records. However, because of event bubbling, one is able to implement more advanced behavior within a Repeater control.
• The display direction of a DataList control can be vertical or horizontal.
• The layout of the DataList control is controlled with the RepeatLayout property.
List of templates available in DataList:
- Works in conjunction with the ItemTemplate to provide a layout for all the odd rows with in the layout.
- Allows for a row or item to be defined on how it looks and behaves when editing.
- Allows the last item in the template to be defined.
- Allows the first item in the template to be defined.
- This is used to define a row or layout for each item in the display.
- It allows for a row or item to be defined on how it looks and behaves when selected.
- This template is used between the items in the template.
Below there is a sample code to create DataList control.
<asp:DataList ID=" dlMyCountry" runat="server">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Country_Code") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Country_Name") %>'></asp:Label>
private void BindGrid()
string sql = "Select * from Country Order By Country_Name";
SqlDataAdapter da = new SqlDataAdapter(sql, “Yourconnectionstring”);
DataTable dt = new DataTable();
dlMyCountry.DataSource = dt;
protected void Page_Load(object sender, EventArgs e)
Found interesting? Add this to: