Hi,
Yes the FindControl only find a direct child in the parent container, since
the GridViewRow implements a marker interface INamingContainer, it will act
as a naming container and you must use its FindControl to find the
CheckBoxList.
As a side note, since the TableCell doesn't implement INamingContainer, we
actually don't need to use .Cells[1].FindControl:
GridView1.Rows[e.RowIndex].FindControl("checklist1") will be fine.
If you can guarantee the control ID is unique in all the descendent
controls in the gridview, you can also use following wrapper function to
find the control recursively:
public static Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
{
return root;
}
foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
{
return t;
}
}
return null;
}
CheckBoxList checklist1 = FindControlRecursive(GridView1, "checklist1") as
CheckBoxList;
Regards,
Walter Wang (, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
|