Solved

VB.Net Dataset Navigation buttons

Posted on 2004-09-01
12
472 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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/…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

10 Experts available now in Live!

Get 1:1 Help Now