.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 12th, 2003, 02:12 PM
wsyeager wsyeager is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Weston, FL
Posts: 32 wsyeager User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via Yahoo to wsyeager
Unhappy multiple listbox selections

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

Reply With Quote
  #2  
Old August 13th, 2003, 10:21 AM
wsyeager wsyeager is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Weston, FL
Posts: 32 wsyeager User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via Yahoo to wsyeager
Question

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")))

Reply With Quote
Reply

Viewing: ASP Free ForumsProgramming.NET Development > multiple listbox selections


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT