下拉式复选框选择取消选择故障

时间:2015-06-09 15:45:06

标签: javascript c# jquery checkbox

我有一个DropDownCheckBoxes

<asp:DropDownCheckBoxes CssClass="FreeTextFilterSelection" ID="cbMarket" AddJQueryReference="false" UseSelectAllNode="True" 
     AutoPostBack="true" DataTextField="Text" runat="server" OnSelectedIndexChanged="cbMarket_SelectedIndexChanged" style="height: 19px" >
     <Texts SelectBoxCaption="" />  
</asp:DropDownCheckBoxes>

和它的SelectedIndexChanged事件

 protected void cbMarket_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string s = string.Empty;
                string s1 = string.Empty;
                int i = 0;
                foreach (ListItem item in (sender as DropDownCheckBoxes).Items)
                {
                    if (item.Selected)
                    {
                        if (i > 0)
                        {
                            s = s + " ...";
                            break;
                        }
                        else
                        {
                            s1 = item.Text;
                            if (string.IsNullOrEmpty(s1))
                                s1 = "NULL";
                            s = s + s1;
                        }
                        i++;
                    }
                }
                (sender as DropDownCheckBoxes).Texts.SelectBoxCaption = s;

            }
            catch (Exception)
            {

            }

        }

当我打开dropdowncheckbox并单击"Select all"时,它会选择全部,当我取消选中Select all时,它会取消选中,但当我想再次检查Select all时,它不会检查所有选项

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我刚刚解决了它

万一有人有同样的问题

aspx部分AddJQueryReference中的

应为true

<asp:DropDownCheckBoxes CssClass="FreeTextFilterSelection" ID="cbMarket" AddJQueryReference="true" UseSelectAllNode="True"
AutoPostBack="true" DataTextField="Text" runat="server" OnSelectedIndexChanged="cbMarket_SelectedIndexChanged" style="height: 19px" >
<Texts SelectBoxCaption="" />
</asp:DropDownCheckBoxes>