Click here to Skip to main content
15,877,591 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am creating List Box . In that list Box I am adding items like Language known that is Kannada,English,Hindi,Tamil, Telugu, Urdu. But here i can select only one item . but can any one suggest me how to select multiple items?
Posted

Set the SelectionMode property to multiple, e.g.

XML
<asp:ListBox SelectionMode="multiple" runat="server" ID="languages">
</asp:ListBox>
 
Share this answer
 
Comments
VJ Reddy 8-Jun-12 5:09am    
Good answer. 5!
codeBegin 8-Jun-12 5:20am    
To the point.. +5
Imran D 8-Jun-12 5:23am    
How To Change the font Style of ListBox Items?
Vani Kulkarni 8-Jun-12 6:12am    
Imran please go through this link : http://forums.asp.net/t/1669523.aspx/1
harshadcse 7-Mar-13 1:50am    
but if i want to select ONLY TWO values..then????
aspx.:
XML
<div>
    <asp:ListBox ID="ListBox1" runat="server">
        <asp:ListItem Value="One" />
        <asp:ListItem Value="Two" />
        <asp:ListItem Value="Three" />
        <asp:ListItem Value="Four" />
        <asp:ListItem Value="Five" />
    </asp:ListBox>
</div>


C#:
C#
protected void Page_Load(object sender, EventArgs e)
{
    ListBox1.SelectionMode = ListSelectionMode.Multiple;
    for (int i = 0; i < ListBox1.Items.Count; i++)
    {
        if(i == 0 || i == 2 || i == 4)
        {
            ListBox1.Items[i].Selected = true;
        }
    }
}

Ref.: Programmatically Select Multiple Items of an ASP.NET ListBox[^]

Refer:
How to select multiple item in ListBox:Asp.net[^]
Cannot select multiple items from listBox.[^]
 
Share this answer
 
Comments
Imran D 8-Jun-12 5:23am    
How To Change the font Style of ListBox Items?
Member 3402886 8-Oct-12 10:09am    
I tried the code above but it doesn't work with a multiple selection Listbox - e.g each time you set one item as Selected the previous one is unselected. Unless I'm missing something??
harshadcse 7-Mar-13 1:50am    
but if i want to select ONLY TWO values..then????

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900