And addition of sorts. This small addition will allow the user to click a
Next and
Previous button to move within the data in the listbox and dynamically update the textboxes/drop downlists displaying the item details.
Add two Webform
button controls, give them appropriate
ID's and add the code for their
OnClick events.
Next Button
Private Sub imgNext_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgNext.Click
' ||||| Move to next Record & re-populate the textboxes/dropdownlists
' |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
' Watch for the range values, as the Items.Count gives the total number of
' items, and the Index values of the listbox are zero based, therefore
' deduct 1 from the count value to get the last index value.
' |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
If lstProducts.SelectedIndex >= lstProducts.Items.Count - 1 Then
lstProducts.SelectedIndex = 0
Else
lstProducts.SelectedIndex += 1
End If
' ||||| Index has now changed, so call the appropriate method
Call lstProducts_SelectedIndexChanged(sender, e)
End Sub
Previous Button
Private Sub imgPrev_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgPrev.Click
' ||||| Move to the previous record in the list
' |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
' Remember that the Index value can not be less than Zero (must be a
' positive number value) and if the Index is at 0, then previous would
' take you to the last item in the list; Count -1
' |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
If lstProducts.SelectedIndex > 0 Then
lstProducts.SelectedIndex -= 1
Else
lstProducts.SelectedIndex = lstProducts.Items.Count - 1
End If
' |||||| Index has now changed, so call the IndexChanged event
Call lstProducts_SelectedIndexChanged(sender, e)
End Sub
It should be noted that I used an
ImageButton control, but you can use the
standard webform button control or even a
HyperLink button control if you want. Just be sure to modify the above code accordingly.
Happy Coding