首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么获得CheckBox选中的数量

2012-12-28 
如何获得CheckBox选中的数量asp:DataList IDDataList_fit runatserver RepeatDirectionHorizonta

如何获得CheckBox选中的数量
<asp:DataList ID="DataList_fit" runat="server" RepeatDirection="Horizontal" Width="100%" >
                                                                                    <ItemTemplate>
                                                                                        <table style="width:110px; border-collapse: collapse;">
                                                                                            <tr>
                                                                                                <td><img src="http://localhost:6771/shoping/shop_admin/product_zsimg/gifts_img/<%# DataBinder.Eval(Container.DataItem,"fitting_img")%>" alt="怎么获得CheckBox选中的数量" style="width:100px; height:100px" /></td>
                                                                                            </tr>
                                                                                            <tr>
                                                                                                <td style="height:30px; vertical-align:top">


                                                                                                    <asp:Label ID="Label14" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "fitting_nm").ToString().Length > 16 ? DataBinder.Eval(Container.DataItem, "fitting_nm").ToString().Substring(0, 16) : DataBinder.Eval(Container.DataItem, "fitting_nm").ToString() %>'></asp:Label>
                                                                                                </td>
                                                                                            </tr>
                                                                                            <tr>
                                                                                                <td style="height:30px; line-height:30px">
                                                                                                    <asp:CheckBox ID="CheckBox1" runat="server" 
                                                                                                        Text='<%# DataBinder.Eval(Container.DataItem,"fitting_price")%>' 


                                                                                                        AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged"/></td>
                                                                                            </tr>
                                                                                        </table>
                                                                                    </ItemTemplate>
                                                                                </asp:DataList>
[解决办法]
<input type='checkbox' id='ChkSelect'  runat="server"  value='<%#Eval("ID")%>'/>
int num = 0;
        for (int i = 0; i < this.AnonalousGrid.Items.Count; i++)
        {
            HtmlInputCheckBox chb = (HtmlInputCheckBox)this.AnonalousGrid.Items[i].FindControl("ChkSelect");      
if (chb.Checked == true)
{
s = s + chb.Value;//chb.Text //服务器端
num++;
}
else
{
num--;
}
}
[解决办法]
$("input:checkbox:checked").size()

[解决办法]
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)


{
        string number = string.Empty;
        for (int i = 0; i < DataList_fit.Items.Count; i++)
        {
            CheckBox cbCheck = DataList_fit.Items[i].FindControl("CheckBox1") as CheckBox;
            if (cbCheck.Checked)
            {
                number = cbCheck.Text;
            }
        }
}
[解决办法]
用jq啦:


<script type="text/javascript">
        $(function () {
            $("#cbxAll").click(function () {
                var flag = $(this).attr("checked");
                $(".subBox :checkbox:enabled").each(function () {
                    $(this).attr("checked", flag);
                });

                $("#hdnIds").val(GetSelectedCustomer());
            });
            var $subcheck = $(".subBox :checkbox:enabled");
            var $check = $("#cbxAll");
            $subcheck.click(function () {
                var flag = true;
                $subcheck.each(function () {
                    if (!this.checked) {
                        flag = false;
                    }
                });
                $check.attr("checked", flag);

                $("#hdnIds").val(GetSelectedCustomer());
            });

        });
        function GetSelectedCustomer() {
            var item = $(".subBox :checkbox:checked").map(function () {
                return $(this).parent().attr("text");


            }).get().join(",");
            return item;
        }
    </script>

撸主你懂的

热点排行