FindControl
2010-08-26 15:37 Tracy. 阅读(360) 评论(0) 编辑 收藏 举报Here is some C# code which should be easy to convert. Pass in the id "lblRecTonT" and the control collection Page.controls or GridView1.Controls. This is guaranteed to work if the ID exists.
public static System.Web.UI.Control FindControl(string controlId, System.Web.UI.ControlCollection controls)
{
for (int counter = 0; counter < controls.Count; ++counter) // loop through each control in the control collection
{
if (controls[counter].ID == controlId) //see if the current control is a match
{
return controls[counter];
}
else if (controls[counter].Controls.Count > 0) // check the child controls
{
System.Web.UI.Control FoundControl = FindControl(controlId, controls[counter].Controls); // recursive call to check child controls
if (FoundControl != null) // control found in child's controls
{
return FoundControl;
}
}
}
return null;
}
本文来自博客园,作者:Tracy.,转载请注明原文链接:https://www.cnblogs.com/tracy/archive/2010/08/26/1809159.html