Gridview Paging and Data Filtering.
-
Hello, This is Vikash Gohil. I have a problem related to Gridview as mentioned below. I have a gridview page that displays All data from a table on page load. Now I have also provided Data Filtering options on the same page for filtering data that is displayed. Now when the user provides a filter condition, gridview only displays the filtered data. But once the user clicks on Next or Previous in the Gridview pager, the filter gets removed and the grid again displays all the data. What I want is the filter condition should remain until the user provides another condition for filtering. How can I go about doing this. Anyone can give me some idea. This would be of great help. Awaiting a reply, Thanks in Advance.
-
Hello, This is Vikash Gohil. I have a problem related to Gridview as mentioned below. I have a gridview page that displays All data from a table on page load. Now I have also provided Data Filtering options on the same page for filtering data that is displayed. Now when the user provides a filter condition, gridview only displays the filtered data. But once the user clicks on Next or Previous in the Gridview pager, the filter gets removed and the grid again displays all the data. What I want is the filter condition should remain until the user provides another condition for filtering. How can I go about doing this. Anyone can give me some idea. This would be of great help. Awaiting a reply, Thanks in Advance.
VikashGohil wrote:
But once the user clicks on Next or Previous in the Gridview pager, the filter gets removed and the grid again displays all the data.
Make sure, you had put this in
IsPostback
condition. Might be grid is getting rebind with the data. Filter client side implemented or server side? -
VikashGohil wrote:
But once the user clicks on Next or Previous in the Gridview pager, the filter gets removed and the grid again displays all the data.
Make sure, you had put this in
IsPostback
condition. Might be grid is getting rebind with the data. Filter client side implemented or server side?Hello, Sandeep. Thanks for the reply. I have Used an SQL DataSource to Bind Data to the Gridview. Initially I had written the Select Command for DataSource in Page_Load event as follows: Page_Load(...) if not page.Ispostback then SDS.ConnectionString = SDS.SelectCommand = GridView.DataSourceID="SDS" GridView.DataBind end if Now the problem here is when first time the page is loaded, the grid displays properly. But when the page postback happens the gridview disappears, bcoz there is no selectcommand in the DataSource. So I have to compulsorily write the above code as below. Page_Load(...) SDS.ConnectionString = SDS.SelectCommand = GridView.DataSourceID="SDS" GridView.DataBind if not page.Ispostback then end if And what do you mean by saying Filtering Client-Side or Server-Side, could you explain a bit about both types. Thanks in Advance, awaiting a reply soon.
-
Hello, Sandeep. Thanks for the reply. I have Used an SQL DataSource to Bind Data to the Gridview. Initially I had written the Select Command for DataSource in Page_Load event as follows: Page_Load(...) if not page.Ispostback then SDS.ConnectionString = SDS.SelectCommand = GridView.DataSourceID="SDS" GridView.DataBind end if Now the problem here is when first time the page is loaded, the grid displays properly. But when the page postback happens the gridview disappears, bcoz there is no selectcommand in the DataSource. So I have to compulsorily write the above code as below. Page_Load(...) SDS.ConnectionString = SDS.SelectCommand = GridView.DataSourceID="SDS" GridView.DataBind if not page.Ispostback then end if And what do you mean by saying Filtering Client-Side or Server-Side, could you explain a bit about both types. Thanks in Advance, awaiting a reply soon.
If you have a Next, Previous button you should be having PageIndexChange event for that GridView. In that event handler you need to "rebind" the data with filter condion that has already been selected. So you need to Save the select query too (using any session management technique ie. ViewState, Hidden field, session variable per your requirement. Hope this helps,
Thanks, Arindam D Tewary