This is a migrated thread and some comments may be shown as answers.

How to retain filter results when page changes (Rad Grid)

4 Answers 344 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 05 Jun 2014, 08:02 AM
Hi All!

I am using custom filter for my RadGrid (I wouldn't post the code here anymore) but my problem is, everything is working fine, but when I change page on the radGrid, it doesn't show anything , but when I click the filter button again it displays the results again 

I tried putting this on my code: 
      protected void RadGrid1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
        {
            RadGrid1.CurrentPageIndex = e.NewPageIndex;
            DBcontrols.filterRadGrid();
            DBcontrols.filterRadGridUsingRange();
            RadGrid1.DataBind();
        }


still No avail, how do I retain the Databind even when changing pages? 

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 05 Jun 2014, 08:27 AM
Hi Joseph,

Please make sure you are binding the grid using Advanced Data-binding (Using NeedDataSource Event).
To perform complex operations such as Inserting, deleting, and updating records through custom edit forms Filtering, Sorting, Paging etc RadGrid must be bound using declarative data sources or through the NeedDataSource event. When using these, RadGrid can automatically accommodate the appropriate database operations without the need for you explicitly handle any sorting, paging, grouping, and so on.

Thanks,
Princy
0
Joseph
Top achievements
Rank 1
answered on 05 Jun 2014, 08:56 AM
Hi,
 I already included 
 SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = new SqlCommand("SELECT * from dbo.transactFile", SQcon);

            DataTable myDataTable = new DataTable();

            SQcon.Open();
            try
            {
                adapter.Fill(myDataTable);
            }
            finally
            {
                SQcon.Close();
            }

            Default._WelPage.RadGrid1.DataSource = myDataTable;


it is still not working

0
Joseph
Top achievements
Rank 1
answered on 05 Jun 2014, 09:03 AM
I included .DataBind and everything is working now thanks 
0
shakeel
Top achievements
Rank 1
Iron
answered on 24 Jan 2024, 01:44 PM

Dear Support team,

I want to retain ASP.NET RadGrid filter values after a page refresh or reload. I have created two functions, 'SaveGridFilters()' and 'RestoreGridFilters()'. 'SaveGridFilters()' sets the current values in the session, and 'RestoreGridFilters()' assigns the values to the filters. However, my issue is that the filter values are set in the current filter column, but the grid doesn't filter the rows. like when we entered the values and grid filter the rows. I have shared the server-side code. Please check and guide me. Thanks

  protected void Page_Load(object sender, EventArgs e)
  {

          if (!Page.IsPostBack)
          {
              RestoreGridFilters();
          }

 protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
 {
     try
     {
             RadGrid1.DataSource = ds.Tables[0];
     }
     catch
     { }
 }

    private void RestoreGridFilters()
    {

        if (Session["GridFilters"] != null)
        {

            Dictionary<string, string> filters = (Dictionary<string, string>)Session["GridFilters"];

            RadGrid1.MasterTableView.FilterExpression = string.Empty;

            foreach (var column in filters.Keys)
            {
                // RadGrid1.MasterTableView.GetColumn(column).CurrentFilterFunction = GridKnownFunction.Contains;
                RadGrid1.MasterTableView.GetColumn(column).CurrentFilterValue = filters[column];

            }


        }
    }

    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.FilterCommandName)
        {
            SaveGridFilters();

        }
    }

    private void SaveGridFilters()
    {
        Dictionary<string, string> filters = new Dictionary<string, string>();
        Session["GridFilters"] = null;
        foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns)
        {
            if (!string.IsNullOrEmpty(column.CurrentFilterValue))
            {
                filters[column.UniqueName] = column.CurrentFilterValue;
            }
        }

        Session["GridFilters"] = filters;
    }

               
Vasko
Telerik team
commented on 29 Jan 2024, 09:59 AM

Hello Shakeel,

You can take advantage of the RadPersistence Framework to save the Grid setting including columns state. You can then save it somewhere (session, database, file, etc..) which can be restored later on demand.

Here are some articles explaining how to utilize the Persisteince Framework:

See the list of supported controls for the Persistence Framework: Supported Controls

I hope this helps you out.

Kind regards,
Vasko
Progress Telerik

Tags
Grid
Asked by
Joseph
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Joseph
Top achievements
Rank 1
shakeel
Top achievements
Rank 1
Iron
Share this question
or