View Complete Post
Please can you give me the code for gridview sorting,paging and cancel and please also explain methe code for each line.....otherwise i wont understand the code
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"];
I have looked at several posts on Gridview sorting but can't seem to get it to work in my code. I am using Subsonic objects as the DataSource. Every time I click on a page or sorting link it does a postback but the page orientation is left at the top, not where the gridview is on the page. Is there a way around this?
This is the code I have written for it:
The issue is two fold in my ASP.NET Web Application. I need to use a custom Distinct() via LINQ to SQL, and then assign thevar as a DataSource to a GridView. If I use the custom Distinct that implements IEqualityComparer, I get "Unsupported overload used for query operator 'Distinct'" exception. but if i somehow get past this, i get "The data source does not support server-side data paging" exception on GridView.DataBind(). here is the code:
(from emp in wsq.LIT_Active_Employees
where (String.IsNullOrEmpty(ssFirstName.Text) ? (emp.FIRST_NAME == null || emp.FIRST_NAME.StartsWith(String.Empty)) : emp.FIRST_NAME.Contains(ssFirstName.Text)) &&
(String.IsNullOrEmpty(ssLastName.Text) ? (emp.LAST_NAME == null || emp.LAST_NAME.StartsWith(String.Empty)) : emp.LAST_NAME.Contains(ssLastName.Text)) &&a