|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 Yeager BCIP, MCP BrainBench Certified Internet Professional Microsoft Certified Professional |
|
#2
|
|||
|
|||
|
I figured it out. However, there is one thing I'm confused about though. The following statement I have for my other listbox in the DataGrid1_ItemDataBound event which is a single selection listbox:
lstCrewChiefTemp.SelectedIndex = lstCrewChiefTemp.Items.IndexOf(lstCrewChiefTemp.It ems.FindByValue(e.Item.DataItem("Username"))) The above statement automatically selects the value in the listbox without apparantly comparing it to anything else to see if it matches (like I did in the multiple listbox - following example): Note: the "Username" is the DataValueField for the listbox and I have a datasource associated with it: DsCrewChief1 For i = 0 To DsCalDteRider1.CalDteRiders.Rows.Count If DsCalDteRider1.CalDteRiders.Item(i).Username = DsRider1.Riders.Item(i).Username Then strUsername = DsRider1.Riders.Item(i).Username lstRiderTemp.Items.FindByValue(strUsername).Select ed = True bytFoundCnt += bytFoundCnt If bytFoundCnt = 2 Then 'Max selections allowed Exit For End If End If Next How does this statement work correctly in selecting the proper listitems??? lstCrewChiefTemp.SelectedIndex = lstCrewChiefTemp.Items.IndexOf(lstCrewChiefTemp.It ems.FindByValue(e.Item.DataItem("Username"))) |
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > multiple listbox selections |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|