asp.net.ph

BaseDataList.Controls Property

System.Web.UI.WebControls Namespace   BaseDataList Class


Returns the collection of child controls for a specified data listing control.

Syntax


Script [ ControlCollection variable = ] BaseDataList.Controls

This property can only be used programmatically; it cannot be set when declaring the control.

Property Value


variable Returns a ControlCollection object that represents the child controls for the specified data listing control.

Remarks

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.

Example

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>" );
   }
}
  C# VB

 Show me 

See Also

BaseDataList Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph