Take the 2-minute tour ×

I have a list box in which i have multiple value

<asp:ListBox ID="lstbox" runat="server" SelectionMode="Multiple" Width="120px">
<asp:ListItem Value="0">None</asp:ListItem>
<asp:ListItem Value="8">Rohan</asp:ListItem>
<asp:ListItem Value="16">Jems</asp:ListItem>
<asp:ListItem Value="64">Tena</asp:ListItem>
<asp:ListItem Value="4">Marry</asp:ListItem>
<asp:ListItem Value="2">Pinky</asp:ListItem>
<asp:ListItem Value="32">Coral</asp:ListItem>
<asp:ListItem Value="1">Dev</asp:ListItem>
<asp:ListItem Value="128">Sam</asp:ListItem>

at once i want to select either one item or more than one and one selected index change i am calling a method

    protected void lstbox_SelectedIndexChanged(object sender, EventArgs e)
        Presenter.getRoles();//filling a grid from database call

    public void getRoles()
        int proid = 0;
        int per=0;
        if (View.UPrivileges.Count > 0)
            proid = Convert.ToInt32(View.UPrivileges.SelectedValue);//listbox selection
            per= Convert.ToInt32(View.Products.SelectedValue);// i have a ddl product checking the value
        if (proid != 0 || per !=0)
            View.Ownerid = per.ToString();
            View.Role = (CRole)proid;
            list.AddRange(userDao.GetUserRolesForItems(View.Role, View.Ownerid));// query method call            View.UserListItems.List = list;
            View.UserListItems.TotalRowCount = list.Count;

when i am selecting 1 value then its working fine but for more than one items giving error, I want to know whether its possible with selectedIndexChange or not, if yes how if not then how to do it on one button click

share|improve this question
Need more info. What is the error you're seeing? What does getRoles() do? Please show the code where you're accessing the list to get the selected items. Also, as currently shown, your list doesn't actually define the callback to lstbox_SelectedIndexChanged() - I assume that's an oversight? –  mikemanne Sep 29 '11 at 12:26
I see you've added some more code, but it doesn't seem like that code is referencing your defined "lstbox". You also still haven't told us anything about the error you're getting. –  mikemanne Sep 29 '11 at 13:33
I have removed that part of code, Can anyone please tell me how can i select multiple value of listbox? –  Rocky Sep 30 '11 at 9:46

1 Answer 1

up vote 1 down vote accepted

this may help

    foreach (ListItem item in lstbox.Items)
            if (item.Selected)
               //code here

share|improve this answer

Your Answer


