LINQ and GridView Paging...
-
I have a problem. I have created a LINQ query and bind it to a gridview and it works but if I enable Allowpaging = true i get this error: The data source does not support server-side data paging. Can anyone tell me how I can work around this? I have set the gridview to Allowpaging=true and EnableSortingAndPagingCallbacks=true but it still won't work! My Code:
protected void GetCasesByID(DataSet ds) { if (IsLoggedIn == false) { gv\_CaseDetails.DataSource = from a in ds.Tables\[0\].AsEnumerable() from b in ds.Tables\[2\].AsEnumerable() where a.Field<string>("CaseId") == txtCaseID.Text && a.Field<string>("Password") == txtPassword.Text select new { CaseManager = a.Field<string>("CaseManager"), NoteCreated = b.Field<string>("NoteCreated"), NoteContent = b.Field<string>("NoteContent"), }; gv\_CaseDetails.DataBind(); IsLoggedIn = true; } }
Illegal Operation
-
I have a problem. I have created a LINQ query and bind it to a gridview and it works but if I enable Allowpaging = true i get this error: The data source does not support server-side data paging. Can anyone tell me how I can work around this? I have set the gridview to Allowpaging=true and EnableSortingAndPagingCallbacks=true but it still won't work! My Code:
protected void GetCasesByID(DataSet ds) { if (IsLoggedIn == false) { gv\_CaseDetails.DataSource = from a in ds.Tables\[0\].AsEnumerable() from b in ds.Tables\[2\].AsEnumerable() where a.Field<string>("CaseId") == txtCaseID.Text && a.Field<string>("Password") == txtPassword.Text select new { CaseManager = a.Field<string>("CaseManager"), NoteCreated = b.Field<string>("NoteCreated"), NoteContent = b.Field<string>("NoteContent"), }; gv\_CaseDetails.DataBind(); IsLoggedIn = true; } }
Illegal Operation
I think the error is self-explanatory. The gridview does not have a way to page because the datasource isn't pageable.. If paging is required, databind the gridview to an ObjectDataSource. Then write a paged select and pagecount function for your data. You'll need to define a class or struct to hold the resultset as well.. e.g. [
DataObject(true)]
public class MyDataSource
{[DataObjectMethod(Select)]
public static *somereturntype* SelectPaged( *params*, int startRowIndex, int maximumRows )
{
// do paged select
}public static int SelectRowCount( *params*, int startRowIndex, int maximumRows )
{
// compute total rowcount
}
}'Howard