遍历控件问题
我在页面建立一个服务器端空间 <div id= "lblout " runat= "server "> </div>
在页面初始化得时候动态加载服务器端控件(checkBox),语法为
strOut = strOut + " <td> <input runat=server type= " "checkbox " " name= " "chkDept " " id= " "chkDept1 " " value=checkAAA> " + "AAA " + " </td> "
strOut = strOut + " <td> <input runat=server type= " "checkbox " " name= " "chkDept " " id= " "chkDept1 " " value=checkBBB> " + "BBB " + " </td> "
Me.lblout.InnerHtml = strOut
我如何遍历生成checkBox控件?
我试过用Page.Controls不行!
------解决方案--------------------我没有听懂你的意思。不过帮顶。
------解决方案--------------------可以查看源码 看看生成的ID 看看后台能不能循环编译得到值
------解决方案--------------------用dom试试
------解决方案--------------------用js getElementByTags也行~~
------解决方案--------------------Page.Controls[1].Controls?试过没有?
------解决方案--------------------strOut = strOut + " <td> <input runat=server type= " "checkbox " " name= " "chkDept " " id= " "chkDept1 " " value=checkAAA> " + "AAA " + " </td> "
strOut = strOut + " <td> <input runat=server type= " "checkbox " " name= " "chkDept " " id= " "chkDept1 " " value=checkBBB> " + "BBB " + " </td> "
Me.lblout.InnerHtml = strOut
-----------------------
你这样绝对能动态创建控件吗,不能吧。
用lblout.Controls.Add()方法动态添加控件
------解决方案--------------------1.用controls.add(checkbox);--这个是服务器端的
2.用html lbl.innerhtml= " <input type=checkbox> "--不用加runat=server,这个是客户端的
------解决方案--------------------帮忙顶
------解决方案--------------------checkbox lock = new checkbox();
lock.Id = "ck1 ";
lock.其他属性= " ";
lblout.controls.add(lock);
foreach (object obj in lblout.controls )
{
}