Gridview paging and sorting using object datasource
Add an Answer
Your question has been submitted and is awaiting moderation.
I've been trying to resolve an issue with paging and sorting with an objectdatasource for a while now and it's giving me a headache :( Keep getting this error :- "The data source does not support server-side data paging." when I click on a sortable column
The paging works fine, but if turned off, sorting is then usable.
Below is a snippet of my code that is in the gridview sorting event. I get the criteria, put it in the string, then call the controller to populate the Info list. The data source is assigned with LINQ where depending on the sort expression, it'll order the list in ascending or descending order then stores the sort expression into the viewstate.
String FilterCriteria = FilterTextbox.Text;
List DSList = Controller.GetItems(FilterCriteria);
if (e.SortExpression == "MyColumn")
if (ViewState["SortExpression"] != null && ViewState["SortExpression"].ToString() == "MyColumn")
MyGridview.DataSource = DSList.OrderByDescending(x => x.MyColumn);
ViewState["SortExpression"] = null;
MyGridview.DataSource = DSList.OrderBy(x => x.MyColumn);
ViewState["SortExpression"] = e.SortExpression;
MyGridview.DataBind(); //Throws error
e.Cancel = true;