User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 422,558 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,697 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting

Populating & Retrieving Data in a listbox : ASP.NET (w/ VB.NET)

Join Date: Feb 2003
Location: Canada
Posts: 786
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Rep Power: 9
Solved Threads: 25
Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Adding Next & Previous Record Controls

  #3  
Jun 3rd, 2004
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
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
Reply With Quote  
All times are GMT -4. The time now is 1:17 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC