multiple selection listbox

wsyeager

Centurion
Joined
Apr 10, 2003
Messages
140
Location
Weston, FL
Is there a way to set the scroll position of a 1 row multiple selection listbox that is a template column from within the datagrid?

After I get values back from my db, I want to set the value to the first position that is selected in this listbox.

It always goes to the first position in the listbox.......

Here is my code:
<code>
For Each drShiftDate In dr
drRider = DsRider1.Riders.FindByUserID(drShiftDate.UserID) 'Find the UserID in the Rider listbox
If Not drRider Is Nothing Then
lstRiderTemp.Items.FindByValue(drShiftDate.UserID).Selected = True
lstRiderTemp.SelectedIndex = lstRiderTemp.Items.IndexOf(lstRiderTemp.Items.FindByValue(drShiftDate.UserID))
End If
End If
Next
</code>
 
Can someone please explain to me why the following code is not working:

<code>
Dim li As ListItem
Dim z As Byte = 0
For Each li In lstSelectionRider.Items
If li.Selected = True Then
strRowNbr = "OrigRider" & z & "UserID" & bytRowNbr
viewstate.Item(strRowNbr) = strRiderUserName(0) End If
z += 1
li.Selected = False
End If
Next</code>

All I want to see is the item going inside the "IF" statement which it never does. Why??? I have the item selected in the listbox, and I'm hitting the "For Each" statement, but it never goes inside the "IF".....
 
RE: Why?

I know this answer is a long time coming (and I'm sure it's been figured out already), but for the sake of people searching for answers to problems they're experiencing now, here's the code that will work in this situation (VB.NET):

Code:
Dim j as Integer
Dim z As Integer
For j=0 To lstSelectionRider.Items.Count - 1
If lstSelectionRider.Items(j).Selected Then
strRowNbr = "OrigRider" & z & "UserID" & bytRowNbr
viewstate.Item(strRowNbr) = strRiderUserName(0)
z = z + 1
li.Selected = False
End If
Next

That, and removing the extra "EndIf" from the code... :-\
 
Back
Top