Last post May 17, 2011 03:57 PM by maximusmd
May 13, 2011 11:25 AM|maximusmd|LINK
I have found and tested many samples out there and later realized they were not working because my Gridview is actually binding to a DataTable.
The reason for that is that before binding it I am adding extra columns in my DataTable.
I am looking for a good sample code which will show me how to show a Gridview with Sorting and Paging features. I know that can easily be done with SqlDataSource, ObjectDataSrouce or even LINQ to SQL but since I am modifying the Table structure on the fly
I am not sure how to implement Paging and Sorting in this situation.
Here is part of my code:
//Load New values from table
DataTable dtNewRecords = FillDataGridView_JobHistory(dateBegin, dateEnd, jobName, clientName);
if ( dtNewRecords != null )
//Finally bind the gridview
GridView2.DataSource = dtNewRecords;
//Sort by the selected column
dtNewRecords.DefaultView.Sort = (String)ViewState["SortExpression"] + " " + (String)ViewState["SortDirection"];
May 13, 2011 12:10 PM|ramsunder1882|LINK
read below link it may be helpful for u
May 13, 2011 04:12 PM|maximusmd|LINK
Hello there, thanks for your answer. It was actually very simple to implement but I realized that it brings ALL the rows.
Since my table is HUGE this is something I cannot apply to our environment :(
May 13, 2011 06:05 PM|maximusmd|LINK
This is CLOSE!!!:
but still fetches ALL records and then filter them in a list for display.
I think LINQ could be a solution here but I have no experience on that area.
May 15, 2011 10:34 PM|Decker Dong - MSFT|LINK
If you want to do paging and sorting manually with DataTable + GridView, see this:
Hope this helps;
May 17, 2011 03:56 PM|maximusmd|LINK
This still returns ALL records from database.
May 17, 2011 03:57 PM|maximusmd|LINK
Found the solution for my problem here: