We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,167 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to create Next,Previous button codings?

Hi,
In .NET i used the follwing codings for the Next and Previous buttons for Navigating the records. but it showed error. In NextButton_Click...

[dim Rec_count = 0] -> this is globally declared.
[dim Row_count as Integer = Data.Tables(0).Rows.Count - 1]
[ If Rec_count <> Row_count Then]
[ Rec_count = Rec_count + 1]
[ TextBox1.Text = Data.Tables(0).Rows(Rec_count).item(0) ]
[ TextBox1.Text = Data.Tables(0).Rows(Rec_count).item(1) ]
[ TextBox3.Text = Data.Tables(0).Rows(Rec_count).item(2) ]
[ Else ]
[ MsgBox " This is last record " ]

So by writing coding like this, for the first time it goes to next record, but if i again click the next button, it doesnt go. it just shows the same record.
So only once it goes to the next record.
same coding for Previous Button also. Only one change is ...

[ Rec_count = Rec_count - 1 ]

. So can anyone help me for the navigation codings??

4
Contributors
3
Replies
2 Years
Discussion Span
2 Years Ago
Last Updated
8
Views
preethi_ga
Light Poster
38 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
'Variables
    Dim rowNum As Integer = 0
    Dim dbMaxNumRows As Integer = dbDataSet.Tables("Dataset").Rows.Count - 1

    'Moves forward a record
    Private Sub btNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btNext.Click
        'If the current row number doesn't not equal the max number of rows
        If rowNum <> dbMaxNumRows Then
            'add one onto the row number
            rowNum = rowNum + 1
            'Fill in all the relevent fields
            Field1.Text = dbDataSet.Tables("Dataset").Rows(rowNum).Item("Var1")
            Field2.Text = dbDataSet.Tables("Dataset").Rows(rowNum).Item("Var2")
            Field3.Text = dbDataSet.Tables("Dataset").Rows(rowNum).Item("Var3")
        Else
            'Else if the row number does equal the maximum number of fields
            'Go to the first record, a loop hey? :)
            rowNum = 0
            'Fill in all the needed fields
            Field1.Text = dbDataSet.Tables("Dataset").Rows(rowNum).Item("Var1")
            Field2.Text = dbDataSet.Tables("Dataset").Rows(rowNum).Item("Var2")
            Field3.Text = dbDataSet.Tables("Dataset").Rows(rowNum).Item("Var3")
        End If
    End Sub

Although slightly different as far as I'm aware of this works. I've watered this version down a bit from the one I've used to make it clearer. In this version it loops instead of just ending, but you can change this. I'm not sure where you went wrong though. But if anyone can compare them and point it out that'd be good. I hope this helps, I'm hoping this works to as I've not tested it since I've removed and changed stuff from what it originally was.

BluePaper
Light Poster
32 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I think it is a better option to use a binding source to solve your problem.

You can attach data to a component using the following-

dim ds as new dataset
dim bs as new bindingsource(ds,"<table name>")

me.textbox1.databindings.add("Text",bs,"<field name>")

Next button- bs.Movenext()

Previous- bs.MovePrevious()

tuse
Junior Poster
174 posts since Jul 2007
Reputation Points: 32
Solved Threads: 14
Skill Endorsements: 0

I have creat one project in there one customer_form & supplier_form
i want to showing record to using to next button
if we click next button then show next record
i dn't know code.

123dev
Newbie Poster
1 post since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0676 seconds using 2.68MB