My Photo
Name:
Location: United States

Tuesday, May 02, 2006

In Search Of ASP.Net Controls

Tips for locating controls with the FindControl method, including finding controls in DataGrid rows, Repeaters, DataGrid headers, and user controls

more at:
http://www.odetocode.com/Articles/116.aspx

FindControl method -
Searches the current naming container for the specified server control.

Here we can see there are many instances of TextBox1, but each ID is prefixed with some additional identifier information. This behavior shows the INamingContainer objects at work. The DataGrid implements INamingContainer and will preface each child control ID with ‘DataGrid1’. As we will see shortly, a DataGrid uses a collection of DataGridItem controls to represent each row of data. A DataGridItem control also implements INamingContainer, and will preface the name of child controls with a it’s own generated identifier (‘_ctrl2’, ‘_ctrl3’, etc.).


to get controls in the footer...
int footerIndex = DataGrid1.Controls[0].Controls.Count-1;
d = DataGrid1.Controls[0].Controls[footerIndex].FindControl("DropDownList1") as DropDownList;

0 Comments:

Post a Comment

<< Home