Click here to Skip to main content
14,176,425 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello guys.I have a two buttons btn_Next and btn_Back and DataTable which is populated from database through a Adapter.
I want that after Database is Populated When i pressbtn_Next or btn_Back i can iterate over rows so if i press btn_Next row index 1 must be selected in response and if i press btn_Back rows index 0 and so on.

What I have tried:

I tried to count rows of datatable and then use it as length of datatable rows and for every click on btn_Next or btn_Back i m increasing or decreasing index accordingly.but i don't know where to use this index and how to use.
Updated 12-Oct-18 2:16am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

private int _currRow =0; // declared in the class before any methods
private Datatable _theData // instaniated  somewhere in the class
private DataRow _dataRow;
private DataRow btn_Next_clicked(object sender, EventArgs e)
   _dataRow =_theTable.Rows[_currRow];

I'll leave the prev button action for you
Danish Kareem 13-Oct-18 17:04pm
Thank you!it is working just like i want after some modification if(_currRow<_theData.Rows.Count - 1)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190525.1 | Last Updated 12 Oct 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100