Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Converting a Unit to an Integer in a control


Message #1 by Imar@S... on Thu, 30 Jan 2003 20:20:29
Hi arnab

If you have bound data to the listboxes (you can't use a drop down as they 
don't allow for multiple choices), you can simply iterate through all the 
items in the list and find out whether they are checked or not:

Suppose you have the following (unbound) listbox:

<asp:ListBox id="ListBox1" runat="server" selectionmode="Multiple">
         <asp:listitem value="1">1</asp:listitem>
         <asp:listitem value="2">2</asp:listitem>
         <asp:listitem value="3">3</asp:listitem>
         <asp:listitem value="4">4</asp:listitem>
</asp:ListBox>

<asp:label id="lblValues" runat="server" /><asp:Button id=Button1 
runat="server" Text="Button"></asp:Button>


To get the values of the selected items at the server, use this:

         Dim aListItem As ListItem
         Dim sValues As String
         For Each aListItem In ListBox1.Items
             If aListItem.Selected = True Then
                 sValues = sValues & aListItem.Text & " is selected<br />"
             End If
             lblValues.Text = sValues
         Next

This will dump the values of the selected items in the Text property of the 
Label lblValues.

There are quite a few good examples in the MSDN docs about this.

Cheers,

Imar



At 12:52 PM 1/30/2003 -0800, you wrote:
>hi Imar,
>
>
>i am new to dot net. can u help me with the
>code(vb.net) to access data from the selection of
>   three dropdownlist into a datagrid. each
>dropdown list will have multiple choices. i am
>using 'ms access'.
>
>thanks
>arnab



  Return to Index