How to enable multi-selecting in ASP.NET CheckBoxList control?

試著忘記壹切 提交于 2019-12-12 02:35:30

问题


I've been struggling with this, is there a way to do it using just configuration? Do I necessarily have to handle multi-selection manually, with post-backs?

<asp:CheckBoxList ID="uxVisibilityScopeCheckBoxList" runat="server" AutoPostBack="false" />    

This definition only allows 1 checkbox to be selected.

Thanks!

EDIT:

Turns out we had a jscript somewhere deep, that was hooking to all of the input[type=checkbox] controls, and allowing to select only 1 checkbox of a same group.

Gotta be careful with those.


回答1:


<asp:CheckBoxList id="check1" AutoPostBack="false"
TextAlign="Right" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:CheckBoxList>

Also look at this link

http://www.w3schools.com/aspnet/showasp.asp?filename=demo_checkboxlist




回答2:


    public static Dictionary<int, string> ListDayWeek()
    {
        var days = new Dictionary<int, string>();
        days.Add(1, "Monday");
        days.Add(2, "Tuesday");
        days.Add(3, "Wednesday");
        days.Add(4, "Thursday");
        days.Add(5, "Friday");
        return days;
    }

       DropDownItem.DataSource = GlobalVar.ListItem();
       DropDownItem.DataValueField = "Key";
       DropDownItem.DataTextField = "Value";
       DropDownItem.DataBind();



回答3:


Here is what you need:

<asp:CheckBoxList ID="uxVisibilityScopeCheckBoxList" runat="server" AutoPostBack="false" >
    <asp:ListItem Value="1">Mercury</asp:ListItem>
    <asp:ListItem Value="2">Venus</asp:ListItem>
</asp:CheckBoxList>



回答4:


Turns out we had a jscript somewhere deep, that was hooking to all of the input[type=checkbox] controls, and allowing to select only 1 checkbox of a same group.

Gotta be careful with those.



来源:https://stackoverflow.com/questions/13836540/how-to-enable-multi-selecting-in-asp-net-checkboxlist-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!