navigating records

santel

Newcomer
Joined
Jun 21, 2005
Messages
7
Hi,
I am very new to asp.net. I want to use two buttons to navigate records backward and forwarded. How could do so. Any help pls
 
If you are using a DataGrid you can just enable paging. If you are using a DataList, DataRepeater, or something you custom made you will have to implement your own solution.

If you are looking to just show one record at a time in some sort of custom solution then if it were me I would have a DataSet that I kept in session of all the records. I would have a variable that holds the current record (index) being shown, and I would have to buttons (next and previous) to move the index forward or back respectively...actually I would implement something more complicated than that but let's keep things simple. I would have the next and previous have logic checks for going past the number or records or going below 0, then my controls on the page would bind to the record of the referenced table in the dataset at the specified index. Then of coarse I would have error handling and clean up code where necessary.

Hope that helps.
 
I am trying to display the fields in textbox and i am using dataset. I dont know how to get the current record index and move backward.(i can move forward using datareader)
Thanks in advance
 
A data reader only moves forward. You will have to use a dataset and track the index yourself....when they open the page they will be at index 0 (the first record of the table in the dataset), moving forward you set the index to 1 (now the second record is displayed), moving backward you set the index back to 0 (now the previous record is displayed), and so on...the syntax would be something like

myRow = myDataSet.Tables("TableWhatever")(myIndex)

And then your controls would bind to the columns of that row.

Also, if you are leaving a data reader open while a user is navigating forward then you are using the data reader incorrectly. A data reader should be used to fill a data set, or a collection of objects, or anything other than for navigational purpose of data. ADO.NET is disconnected data, that is the beauty of it, the DataSet represents the source data and allows you to navigate and manipulate it without tying up database connections (which are limited and in the real world a DBA will kick you to the curb if your keeping a connection open just for navigation purposes). Follow my instructions in this post and the previous and I gaurantee it will work for you.
 
Back
Top