首页 新闻 会员 周边

判断CheckBoxList在当前点击的时候是否选中

0
悬赏园豆:50 [已解决问题] 解决于 2009-04-30 10:43

CheckBoxList是后台代码动态生成的,现在我要在前台点击CheckBoxList生成的子项的时候判断是否选中. 如果选中显示一个层,否则隐藏层, 功能主要 就是我CheckBoxList循环出来的是部门,选中部门的时候我要在层里显示这个部门里的人员

 

问题补充: 能给点代码之类的吗; IList<DepartInfoInfo> Depart = DepartInfoManager.SelectOneDepart(depart); foreach (DepartInfoInfo item in Depart) { ListItem li = new ListItem(); li.Value = "" + item.ID; li.Text = item.DepartName; this.cblDepart.Items.Add(li); } <asp:CheckBoxList ID="cblDepart" runat="server" RepeatDirection="Horizontal" nclick="javascript:createDiv(this)" > </asp:CheckBoxList> function createDiv(check) { var xxxDIV = document.getElementById(check) var shadow = document.createElement("div"); shadow.setAttribute("id", "shadow"); shadow.style.zIndex = "10"; if (xxxDIV.checked) { var box = document.getElementById("GridViewDIV"); box.style.zIndex = "999"; box.style.top = "40%"; box.style.left = "40%"; document.body.appendChild(shadow); box.style.display = ""; } else { hideDiv() } } function hideDiv() { var box = document.getElementById("GridViewDIV"); var shadow = document.getElementById("shadow"); box.style.display = "none"; box.style.zIndex = "0"; box.style.top = "0"; box.style.left = "0"; document.body.removeChild(shadow); } 我写的代码是这样的,可JS获取不到他的ID 获取的是空
杨杰828的主页 杨杰828 | 初学一级 | 园豆:160
提问于:2009-04-29 10:54
< >
分享
最佳答案
0

foreach (DepartInfoInfo item in Depart)
{
ListItem li = new ListItem();
li.Value = "" + item.ID;
li.Text = item.DepartName;

 li.Attributes.Add("onclick","createDiv(this)");   //事件绑定

this.cblDepart.Items.Add(li); 

 

}

 

<asp:CheckBoxList ID="cblDepart" runat="server" 
RepeatDirection="Horizontal" onclick="javascript:createDiv(this)"> 绑定错误

黑白之间 | 小虾三级 |园豆:859 | 2009-04-29 20:51
其他回答(2)
0

在控件ITEM里绑定注册JS onclick事件即可

yeyang | 园豆:418 (菜鸟二级) | 2009-04-29 10:59
0

<asp:CheckBoxList ID="cblDepart" runat="server"
RepeatDirection="Horizontal" nclick="javascript:createDiv(this)"></asp:CheckBoxList>错误!把点击的事件写在Item绑定信息的时候,item.Attributes["checkBox变更的事件"].add()

就可以了

邢少 | 园豆:10926 (专家六级) | 2009-04-29 11:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册