Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Help with moving through records in datatables

Posted on 2011-10-16
11
Medium Priority
?
177 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:vcharles
  • 6
  • 5
11 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36976513
> 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
0
 

Author Comment

by:vcharles
ID: 36976534
I'm using Button click event to Move Next, Previous,Last and First, what is the propoer syntax for each button click events?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36976540
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vcharles
ID: 36976569
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.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 36976635
And show one record in dropdownlist or a textbox?

Here is a skeleton


Page Load:
If Not Page.IsPostBack Then
   ...
   Session("CurrentIndex") = 0
   Session("dtDonor") = dtDonor
End If

Next Click:
dtDonor = Session("dtDonor")
CurrentIndex = Session("CurrentIndex")
If CurrentIndex < dtDonor.Rows.Count - 1 Then
   CurrentIndex += 1
   Session("CurrentIndex") = CurrentIndex
   txtDonor.Text = dtDonor.Rows(CurrentIndex).Item("Name")
Next

Previous Click:
dtDonor = Session("dtDonor")
CurrentIndex = Session("CurrentIndex")
If CurrentIndex > 0 Then
   CurrentIndex -= 1
   Session("CurrentIndex") = CurrentIndex
   txtDonor.Text = dtDonor.Rows(CurrentIndex).Item("Name")
Next

First Click:
dtDonor = Session("dtDonor")
CurrentIndex = Session("CurrentIndex")
If dtDonor.Rows.Count > 0 Then
   CurrentIndex = 0
   Session("CurrentIndex") = CurrentIndex
   txtDonor.Text = dtDonor.Rows(CurrentIndex).Item("Name")
Next

Last Click:
dtDonor = Session("dtDonor")
CurrentIndex = Session("CurrentIndex")
If dtDonor.Rows.Count > 0 Then
   CurrentIndex dtDonor.Rows.Count - 1
   Session("CurrentIndex") = CurrentIndex
   txtDonor.Text = dtDonor.Rows(CurrentIndex).Item("Name")
Next

Open in new window

0
 

Author Comment

by:vcharles
ID: 36976653
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,
0
 

Author Comment

by:vcharles
ID: 36976705
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
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36976727
change

currentIndex(dtDonor.Rows.Count - 1)

to

currentIndex = dtDonor.Rows.Count - 1
0
 

Author Comment

by:vcharles
ID: 36976756
Thank You!
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36976764
Glad to help :-)
0
 

Author Comment

by:vcharles
ID: 36976805
I just opened another similar case, hopefully yo can help me solve the next issue.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question