Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with moving through records in datatables

Hello,

I've populated two Dropdownlist with two datatables, How do I move throught the records of the datatables while displaying the data in the dropdownLists? I am using VB.NET with ASP.NET.

        CmbRec.DataSource = dtReceiver
        CmbRec.DataTextField = "Name"
        CmbRec.DataValueField = "ReceiverID"
        CmbRec.DataBind()

        CmbDonor.DataSource = dtDonor
        CmbDonor.DataTextField = "Name"
        CmbDonor.DataValueField = "DonorID"
        CmbDonor.DataBind()

Thanks,

Victor
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

> How do I move throught the records of the datatables

Loop through the tables?

For i As Integer = 0 to dtDonor.Rows.Count - 1
    msgbox dtDonor.Rows(i).Item(0)
Next
Avatar of Victor  Charles

ASKER

I'm using Button click event to Move Next, Previous,Last and First, what is the propoer syntax for each button click events?
In a combobox? Combobox shows all the records! Anyway, you can maintain an index value in a variable which is incremented in Next click and decremented in Previous click.
I know it shows all the records but I only want to see one record at a time. How do I achieve this? Cna you please send me an example of using the index approach.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the code. I meed to use a combobox because when users click on it, I want to display all the data in Receiver and Donor files to give them the capability to change the data from the existing datatable. I will try the code and get back you by tomorrow,
Hi,

I'm getting error:currentIndex is not a method on line currentIndex(dtDonor.Rows.Count - 1)


dtDonor = Session("dtDonor")
        currentIndex = Session("CurrentIndex")
        If dtDonor.Rows.Count > 0 Then
            currentIndex(dtDonor.Rows.Count - 1)
            Session("CurrentIndex") = currentIndex
            CmbRec.Text = dtDonor.Rows(currentIndex).Item("Name")
        End If
change

currentIndex(dtDonor.Rows.Count - 1)

to

currentIndex = dtDonor.Rows.Count - 1
Thank You!
Glad to help :-)
I just opened another similar case, hopefully yo can help me solve the next issue.