System.Web.UI.WebControls Namespace BaseDataList Class
Returns the collection of child controls for a specified data listing control.
Script |
[ ControlCollection variable = ] BaseDataList.Controls |
This property can only be used programmatically; it cannot be set when declaring the control.
variable |
Returns a ControlCollection object that represents the child controls for the specified data listing control. |
The Controls collection enables programmatic access to the child controls contained in a data listing control. You can use this property to obtain information about each control in the collection.
For every header, footer, separator, and data item defined within the opening and closing tags of a DataList or DataGrid, ASP.NET automatically adds one DataListItem or DataGridItem object to the respective Controls collection.
In the case of data items, ASP.NET adds one DataListItem or DataGridItem to the collection for each record in the DataSource.
Any data-bound HTML tags or text strings that are not processed on the server, such as those defined for the Item and AlternatingItem templates of the corresponding class, are treated as DataBoundLiteralControl objects, and are added to the collection.
Any HTML tags or text strings that are not data-bound, such as those defined for the Header and Footer templates of the corresponding class, are treated as LiteralControl objects, and are added to the collection as well.
Like most collections in the .NET Framework, you can add to, remove from, or iterate through the list of items in this collection.
The below snippet shows how to programmatically access the collection of child controls ( as well as their child controls ) in a DataList. In this case, the sample simply determines and displays the type and UniqueID of each child control.
Notice in the output that the first control ( the header item ) contains a child literal control, whereas the rest of the controls ( the data items ) contain data-bound literal controls.
foreach ( Control child in myDataList.Controls ) {
Response.Write ( child.GetType ( ) + " " + child.UniqueID + "<br>" );
foreach ( Control kid in child.Controls )
Response.Write ( child.GetType ( ) + " " + child.UniqueID + "<br>" );
}
}
Dim child As Control
for each child In myDataList.Controls
Response.Write ( child.GetType ( ) + " " + child.UniqueID + "<br>" )
Dim kid As Control
For Each kid In child.Controls
Response.Write ( child.GetType ( ) + " " + child.UniqueID + "<br>" )
Next kid
Next child |
|
C# |
VB |
Show me
BaseDataList Members