首页 新闻 会员 周边 捐助

c# listview外层的checkbox选中时,listview内的所有checkbox全选

0
悬赏园豆:20 [待解决问题]

我的listview外面有一个checkbox,listview里面有checkbox,listview里面checkbox的数量是根据绑定数据的数量个数决定的,现在的如果点击外层的checkbox,listview里面的checkbox却无反应,求解。(请不要随便写类似于“用js啦,很简单的”类似的敷衍性回答)

前端:

 1 <ContentTemplate>
 2 <asp:CheckBox ID="cb_AllSelectRPhoto" runat="server" OnCheckedChanged="cb_AllSelectRPhoto_OnCheckedChanged" AutoPostBack="true" />
 4 <asp:Label ID="lb_SelectAllorNot" runat="server" meta:resourcekey="lb_SelectAllorNot"></asp:Label>
 5 <asp:ListView  ID="lv_SelectRPhoto" runat="server" OnItemDataBound="lv_SelectRPhoto_OnItemDataBound" GroupItemCount="5">
 6 <GroupTemplate>
 7 <tr id="itemPlaceholderContainer" runat="server">
 8 <td id="itemPlaceholder" runat="server">
 9 </td>
10 </tr>
11 </GroupTemplate>
12 <ItemTemplate>
13 <td runat="server" style="width: 150px;">
14 <table>
15 <tr>
16 <asp:HiddenField runat="server" ID="hdf_RowIndex" Value="" />
17 <asp:HiddenField runat="server" ID="hdf_SourcePath" Value="" />
18 <asp:Image runat="server" ID="img_SelectPhoto" ImageUrl="" Width="150px" Height="100px" /><br />
19 <asp:Label runat="server" ID="lbl_SelectPhoto" /><br />
20 <asp:CheckBox runat="server" ID="ckb_SelectPhoto" /></tr>
21 </table>
22 </td>
23 </ItemTemplate>
24 <LayoutTemplate>
25 <table id="Table1" runat="server">
26 <tr runat="server">
27 <td runat="server">
28 <table id="groupPlaceholderContainer" runat="server" border="0" cellpadding="0" style="">
29 <tr id="groupPlaceholder" runat="server">
30 </tr>
31</table>
32 </td>
33 </tr>
34 <tr runat="server">
35 <td runat="server" style="">
36 </td>
37 </tr>
38 </table>
39 </LayoutTemplate>
40 </asp:ListView>
41 </ContentTemplate>

后台代码:

 1 protected void cb_AllSelectRPhoto_OnCheckedChanged(Object sender, EventArgs e)
 2 {            
 3 CheckBox cb_temp = (CheckBox)sender;
 4 if (cb_temp.Checked == true)
 5 {
 6 for (int count = 0; count < lv_SelectRPhoto.Items.Count; count++)
 7 {
 8 CheckBox cb_DataItem_temp = 
 9 (CheckBox)lv_SelectRPhoto.Items[count].FindControl("ckb_SelectPhoto");
10 cb_DataItem_temp.Checked = true;
11 }
12 }
13 else
14 {
15 for (int count = 0; count < lv_SelectRPhoto.Items.Count; count++)
16 {
17 CheckBox cb_DataItem_temp = 
18 (CheckBox)lv_SelectRPhoto.Items[count].FindControl("ckb_SelectPhoto");
19 cb_DataItem_temp.Checked = false;
20 }
21 }
22 }
rivahuang的主页 rivahuang | 初学一级 | 园豆:91
提问于:2016-01-13 17:17
< >
分享
所有回答(2)
0
$("#外层Checkbox的ID").click(function (e) {
            var _this = $(this), _childs = $("input[type=checkbox]", _this);
            _childs.prop("checked", _this.prop("checked"));
        });
写代码的小2B | 园豆:4377 (老鸟四级) | 2016-01-13 17:31
 $("#cb_AllSelectRPhoto").click(function (e) {
             var  _this = $("#<%=cb_AllSelectRPhoto.ClientID %>");
            _childs = $("input[type=checkbox]", _this);
            _childs.prop("checked", _this.prop("checked"));
        });
支持(0) 反对(0) rivahuang | 园豆:91 (初学一级) | 2016-01-13 18:39

无反应阿

支持(0) 反对(0) rivahuang | 园豆:91 (初学一级) | 2016-01-13 18:39
0

楼上的方法可以

搁忆 | 园豆:612 (小虾三级) | 2016-01-13 17:42

h还是不行啊

支持(0) 反对(0) rivahuang | 园豆:91 (初学一级) | 2016-01-13 18:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册