Paging in Datagrid
-
I wiold like to do paging say by 1 , 2, 3 or next/Previous in datagrid (In Win form application) Any Input or Sample code please?
-
I wiold like to do paging say by 1 , 2, 3 or next/Previous in datagrid (In Win form application) Any Input or Sample code please?
It would ask a lot of work, but you can do the following: Create two datasets, one dataset has all the data, the second one only has the records to view (one page at a time). page = 30 records (begins at 0) beginrecord = page * 30 endrecord = (page * 30) + 30 Every time you go to the next or previous page execute the following procedure for the new page (clear the view dataset first):
//This code is an example probably doesnt work this way
string configuredTable = "MyTable";
DataSet myDataSet = new DataSet();for(int index = beginrecord; index < endrecord; index++)
{
DataRow newrow = viewdataset.Tables[configuredTable].NewRow();//TODO: Setup the data in the viewrow
viewdataset.Tables[configuredTable].AddRow(newrow);
}viewdataset.AcceptChanges();
walk through the dataset table with the records you want to display and add them to a separate dataset. (Don't forget to call
AcceptChanges()
) There's one problem though: You should not edit the records in the view dataset, because that one gets cleared every time you change the page. Ofcourse you can implement the DataRowAdded eventhandler and add the same data to the non-view dataset. WM.
What about weapons of mass-construction?