multiple listbox selections

Discussion in 'ASP .Net' started by bill yeager, Aug 12, 2003.

  1. bill yeager

    bill yeager Guest

    Duray, it helps in regards to knowing how to get the items
    that were selected in the lisbox, but I'm going in
    reverse --- after I get the items from the db that were
    selected, I'd like to be able to highlight them in the
    listbox within the datagrid control.........

    Thanks,

    Bill...
    >-----Original Message-----
    >Hi Bill,
    >
    >If you are talking about:
    >System.Object
    > System.Web.UI.Control
    > System.Web.UI.WebControls.WebControl
    > System.Web.UI.WebControls.ListControl
    > System.Web.UI.WebControls.ListBox
    >ther is mo way to get the selected items without

    iterating.
    >
    >Lets say you have ListBox1
    >
    >foreach (ListItem li in myListBox.Items )
    >{
    > if(li.Selected)
    > {
    > // put the code for selected Item
    > }
    >}
    >
    >
    >In VS.NET2003 help:
    >ms-
    >help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frl

    r
    >fsystemwebuiwebcontrolslistboxclassselectionmodetopic.htm
    >
    >Hope It Helps
    >
    >Duray AKAR
    >
    >PS:
    >I have a piece of static code somewhere that gives the
    >selected items for any given
    > System.Web.UI.WebControls.CheckBoxList
    > System.Web.UI.WebControls.DropDownList
    > System.Web.UI.WebControls.ListBox
    > System.Web.UI.WebControls.RadioButtonList
    >controls... Ask if you need something like that
    >
    >
    >>-----Original Message-----
    >>I have a listbox in a datagrid that can contain up to

    two
    >>selections. How can I return the selected indexes of the
    >>two values? I know how to do it for a listbox that has a
    >>selectionmode of "single", but not for multiple.
    >>
    >>Here is my HTML:
    >><asp:TemplateColumn HeaderText="Riders">
    >>
    >> <ItemTemplate>
    >>
    >> <asp:listbox AutoPostBack="False"
    >>BackColor="#ffffff" id="lstRider" runat="server"

    Rows="1"
    >>DataSource="<%# DsRider1 %>" Enabled="True"
    >>SelectionMode="Multiple" DataTextField="UserName"
    >>DataValueField="UserName" SelectedIndex='<%#
    >>GetRiderUserName() %>' />
    >>
    >> </asp:listbox>
    >>
    >> </ItemTemplate>
    >>
    >> </asp:TemplateColumn>
    >>
    >>
    >>I'm executing a function "GetRiderUserName" in my code-
    >>behind to return the selected indices, but don't quite
    >>know how to do it. This is as far as I've got:
    >>
    >> Public Function GetRiderUserName() As Integer
    >>
    >> 'Returns the index of the username
    >> Dim i As Integer
    >> Dim blnFound As Boolean = False
    >> Dim bytFoundCnt As Byte = 0
    >>
    >> For i = 0 To

    >DsCalDteRider1.CalDteRiders.Rows.Count
    >> If DsCalDteRider1.CalDteRiders.Item
    >>(i).Username = DsRider1.Riders.Item(i).Username Then
    >> blnFound = True
    >> If bytFoundCnt = 2 Then 'Max selections
    >>allowed
    >> Exit For
    >> End If
    >> Else
    >> blnFound = False
    >> End If
    >> Next
    >>
    >> If blnFound Then
    >> Return DsRider1.Riders.Item(i).RowNbr
    >> Else
    >> Return -1
    >> End If
    >>
    >> End Function
    >>
    >>How can I turn "Return DsRider1.Riders.Item(i).RowNbr"
    >>into the selected indexes of a possible two selections?
    >>
    >>Thanks,
    >>
    >>Bill
    >>.
    >>

    >.
    >
    bill yeager, Aug 12, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWRpcw==?=
    Replies:
    0
    Views:
    382
    =?Utf-8?B?QWRpcw==?=
    Oct 19, 2004
  2. zdrakec
    Replies:
    0
    Views:
    519
    zdrakec
    Jul 22, 2005
  3. zdrakec
    Replies:
    0
    Views:
    471
    zdrakec
    Jul 22, 2005
  4. Chris Kettenbach

    asp:ListBox multiple selections

    Chris Kettenbach, Oct 7, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    10,321
    S. Justin Gengo
    Oct 7, 2005
  5. bthomasIDFG
    Replies:
    0
    Views:
    135
    bthomasIDFG
    Oct 12, 2005
Loading...

Share This Page