我用递归写了个简单的控件查找函数,返回的控件属于Control类,可是查找的目标控件属于WebControls,强制转换我已经尝试了,报错,大概意思是"无法将Control 转换 为 WebControl"。 private Control SuperFindControl(Control wctrl, string ctrlname)
{
if (wctrl.ID == ctrlname)
{
return wctrl;
}
else
foreach (Control ct in wctrl.Controls)
{
SuperFindControl(ct, ctrlname);
return ct;
}
return null;
}函数没有控件类型,只是单纯的查找用户名; 类型转换一直很让我头疼,还请高手指点指点啊……
{
if (wctrl.ID == ctrlname)
{
return wctrl;
}
else
foreach (Control ct in wctrl.Controls)
{
SuperFindControl(ct, ctrlname);
return ct;
}
return null;
}函数没有控件类型,只是单纯的查找用户名; 类型转换一直很让我头疼,还请高手指点指点啊……
System.Web.UI.WebControls.Label lb;
System.Web.UI.WebControls.DropDownList ddl;
lb = (Label)SuperFindControl(newUp, "lb" + i.ToString());
ddl = (DropDownList)SuperFindControl(newUp, "ddl" + i.ToString());