asp.net.ph

Control.Controls Property

System.Web.UI Namespace   Control Class


Returns the collection of child controls for a specified server control in the UI hierarchy. Also used to add or remove individual control items in the collection.

Syntax


Script [ ControlCollection var = ] Control.Controls

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

Property Value

A ControlCollection object that represents the child controls for the specified server control.

Remarks

On an ASP.NET page, when controls are added declaratively between the opening and closing tags of a server control, ASP.NET automatically adds the controls to the containing server control's ControlCollection. Any HTML tags or text strings that are not processed on the server are treated as LiteralControl objects, and are added to the collection like other server controls.

The Controls property allows programmatic access to the instance of the ControlCollection class for any server control. Like any collection in the .NET Framework, you can add to, remove from, or iterate through the list of items in the collection.

Example

The following example demonstrates how to dynamically add child controls ( TableRow and TableCell controls ) to a Table control using its Controls property.

int numrows=int.Parse ( DropDown1.SelectedItem.Value );
int numcells=int.Parse ( DropDown2.SelectedItem.Value );

for ( int j=0; j<numrows; j++ ) {
   TableRow r=new TableRow ( );
   for ( int i=0; i<numcells; i++ ) {
      TableCell c=new TableCell ( );
      c.Controls.Add ( new LiteralControl ( "row " + j.ToString ( ) + ", cell " + i.ToString ( ) ) );
      r.Cells.Add ( c );
   }
   myTable.Rows.Add ( r );
}

 Show me 

See Also

Control Members   ControlCollection 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