Solved

VB.Net Dataset Navigation buttons

Posted on 2004-09-01
12
470 Views
Last Modified: 2008-01-09
Dears,

1- I have a textbox1 in my aspx page with only one button. The textbox1 is bound to a dataset already filled with data through data adapter. I want to move to the next record in the dataset every time I click the button. How can I,

I tried using this each time the button is pressed, but I failed.

static x as integer
textbox1.text = MyDataset.tables.rows(x)
x= x+1

2- Is it possible to use static variables in the aspx pages, so the variable keep its value.
0
Comment
Question by:HaryMary
  • 4
  • 4
  • 2
  • +1
12 Comments
 
LVL 11

Expert Comment

by:L00M
Comment Utility
I accomplish this using a dataview as follows (I have four buttons: Go First, Go Previous, Go Next, Go Last - Let me know if you need further clarification):

' Global
    Dim CurrentRow As Integer

...
Dim dvHeader As DataView
dvHeader = ds0.Tables(0).DefaultView
...

    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        GoFirst()
    End Sub

    Private Sub GoFirst()
        CurrentRow = 0
        Me.BindingContext(dvHeader).Position = 0
    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        GoPrevious()
    End Sub

    Private Sub GoPrevious()
        CurrentRow -= 1
        If CurrentRow < 0 Then CurrentRow = 0
        Me.BindingContext(dvHeader).Position = CurrentRow
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        GoNext()
    End Sub

    Private Sub GoNext()
        CurrentRow += 1
        If CurrentRow > ds0.Tables(0).Rows.Count - 1 Then CurrentRow = ds0.Tables(0).Rows.Count() - 1
        Me.BindingContext(dvHeader).Position = CurrentRow
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        GoLast()
    End Sub

    Private Sub GoLast()
        CurrentRow = ds0.Tables(0).Rows.Count() - 1
        Me.BindingContext(dvHeader).Position = CurrentRow
    End Sub


Neil Brewer
0
 
LVL 11

Expert Comment

by:L00M
Comment Utility
Also Global:
    Dim dvHeader As DataView
0
 
LVL 7

Expert Comment

by:vnvk
Comment Utility

In your code, there is an error. when you are using static variables, the value will not change, and any incrementation will not work on that. Instead use a normal variable and increment it.

I go with @L00M

You can use a part of his code:

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        GoNext()
    End Sub

    Private Sub GoNext()
        CurrentRow += 1
        If CurrentRow > ds0.Tables(0).Rows.Count - 1 Then CurrentRow = ds0.Tables(0).Rows.Count() - 1
        Me.BindingContext(dvHeader).Position = CurrentRow
    End Sub


to achevie the result you are expecting. Thats more clear and you need not maintain any variables, application takes care of it.
0
 
LVL 11

Expert Comment

by:L00M
Comment Utility
BTW, the reason I put GoNext into a different function is so I could wire up the scroll wheel on the mouse easily:

    Private Sub PatientCard_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseWheel
        If e.Delta < 0 Then
            GoNext()
        Else
            GoPrevious()
        End If
    End Sub

That can be improved upon, but works ok.
NB
0
 
LVL 7

Expert Comment

by:vnvk
Comment Utility
Looks like you are an expert in dotnet programming @L00M
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 11

Expert Comment

by:L00M
Comment Utility
I wouldn't say Expert... more like, thrown into the deep end... swim or drown. ;) It's taken many many hours to even learn how to tread. .NET is nice for some tasks, but it seems like killing a mouse with an elephant gun for so many simple tasks. :)
0
 
LVL 7

Expert Comment

by:vnvk
Comment Utility
hmm, thats true. But, unfortunately, we have to go with it sometimes, till we find an alternative.
Hope that we get a way out soon..
0
 
LVL 1

Author Comment

by:HaryMary
Comment Utility
Friends,

The variable CurrentRow wouldn't keep or store the last value. I tried using global.asax file to declare the CurrentRow variable, but my webform wouldn't have access to that variable ???
 
0
 
LVL 7

Expert Comment

by:vnvk
Comment Utility
Hey, there is some issue that I too noticed with Global Variables in .NET.  As a turnaround, I used a hidden field which was assigned the value of the variable and the value is retrieved wheever required in the post back.

lets say, you have current row=-1 initially, pass on that value to the hidden valriable from CodeBEhind.

When ever you do post back, retrieve the value and again assign it to the hidden field.

Let me check if there are any alternatives available
It would be useful for me also.
0
 
LVL 1

Author Comment

by:HaryMary
Comment Utility
Dears,

The solution is in using ASP.Net and its ViewState property where you can initialize it as follows

If not IsPostBack Then
   Me.ViewState("xx") = 0
Else
   Me.ViewState("xx") = me.ViewState("xx") + 1
End If


Cheers
0
 

Accepted Solution

by:
modulo earned 0 total points
Comment Utility
PAQed with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
post data with a link 8 49
Copy only dates 3 69
XML Parsing Classic ASP 5 42
SQL to update characters in table column 6 25
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now