求助:如何根据id动态取得html控件?具体问题见内
具体问题如下:
前台:
<ul id= "nav ">
<li id= "module0 " runat= "server "> <a href= "# "> 模块一 </a> </li>
<li id= "module1 " runat= "server "> <a href= "# "> 模块二 </a> </li>
<li id= "module2 " runat= "server "> <a href= "# "> 模块三 </a> </li>
<li id= "module3 " runat= "server "> <a href= "# "> 模块四 </a> </li>
</ul>
后台:
string ss= "0101 "
char[] mm = ss.ToCharArray();
for (int i = 0; i < mm.Length; i++)
{
if (Convert.ToInt32(authority[i]) == 1)
//this.module0.Attributes.Add( "style ", "display:none; ");
??????????????????????????????????????????????????????
在这里如何根据i值,取得不同的module,来进行添加属性。
??????????????????????????????????????????????????????
}
谢谢各位大虾。 求教了。
------解决方案--------------------HtmlGenericControl li = this.Page.FindControl( "module " + mm[i]) as HtmlGenericeControl
------解决方案--------------------System.Web.UI.HtmlControls.HtmlGenericControl li = this.Page.FindControl( "module " + mm[i]) as System.Web.UI.HtmlControls.HtmlGenericControl;
li.Attributes.Add( "style ", "display:none; ");