我的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 }
$("#外层Checkbox的ID").click(function (e) { var _this = $(this), _childs = $("input[type=checkbox]", _this); _childs.prop("checked", _this.prop("checked")); });
$("#cb_AllSelectRPhoto").click(function (e) { var _this = $("#<%=cb_AllSelectRPhoto.ClientID %>"); _childs = $("input[type=checkbox]", _this); _childs.prop("checked", _this.prop("checked")); });
无反应阿
楼上的方法可以
h还是不行啊