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
>fsystemwebuiwebcontrolslistboxclassselectionmodet opic.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
>>.
>>
>.
>
|