?
Solved

VB.Net Dataset Navigation buttons

Posted on 2004-09-01
12
Medium Priority
?
491 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

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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

770 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