locked
Problem in multiselect of listbox RRS feed

  • Question

  • User-1872689156 posted

    I've a problem in multiple selection from listbox. I want to select multiple items from listbox and perform a search to my table on that basis. I don't know this is possible or not. If yes then somebody please help me soon.

    Wednesday, November 5, 2008 2:17 AM

Answers

  • User-194310423 posted

    write SelectionMode = "Multiple" as below 

    <asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple"></asp:ListBox>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 5, 2008 3:51 AM
  • User469998836 posted

     Hi Namrata,

    Following is the code that might give you an idea about getting the selected items from a ListBox control:

    You can write this code in the event handler where the values are desired.

     

     

    int[] ind = ListBox1.GetSelectedIndices();
            for (int i = 0; i < ind.Length; i++)
                Response.Write("&lt;br>" + ListBox1.Items[ind[i]].Text);

      

     

    Hope it helps!

    Regards,

    Girish [:D]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 5, 2008 4:35 AM

All replies

  • User-194310423 posted

    write SelectionMode = "Multiple" as below 

    <asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple"></asp:ListBox>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 5, 2008 3:51 AM
  • User-1872689156 posted
    I know this but how could I collect the selected values in respective variables and then write the according select query.
    Wednesday, November 5, 2008 4:22 AM
  • User469998836 posted

     Hi Namrata,

    Following is the code that might give you an idea about getting the selected items from a ListBox control:

    You can write this code in the event handler where the values are desired.

     

     

    int[] ind = ListBox1.GetSelectedIndices();
            for (int i = 0; i < ind.Length; i++)
                Response.Write("&lt;br>" + ListBox1.Items[ind[i]].Text);

      

     

    Hope it helps!

    Regards,

    Girish [:D]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 5, 2008 4:35 AM