Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 12-Oct-18 2:16am

1 solution

C#
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)
{
    
    if(_currRow<_theData.Rows.Count)
    {
      ++_currRow;
     
    }
   _dataRow =_theTable.Rows[_currRow];
  
    
}


I'll leave the prev button action for you
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900