Solved

VB.Net Dataset Navigation buttons

Posted on 2004-09-01
12
481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
12 Comments
 
LVL 11

Expert Comment

by:L00M
ID: 11951732
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
ID: 11951738
Also Global:
    Dim dvHeader As DataView
0
 
LVL 7

Expert Comment

by:vnvk
ID: 11952154

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
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!

 
LVL 11

Expert Comment

by:L00M
ID: 11952256
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
ID: 11952360
Looks like you are an expert in dotnet programming @L00M
0
 
LVL 11

Expert Comment

by:L00M
ID: 11952442
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
ID: 11952546
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
ID: 11971918
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
ID: 11972049
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
ID: 12051785
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
ID: 12743117
PAQed with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP CDO - Limiting Connections 3 66
JQuery on multiple lines 3 16
Read text on Table 7 30
StoredProcedure to JSON query faulty syntax 2 29
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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