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

[Solved] RadGrid stuck at second page

1 Answer 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
KocSistem
Top achievements
Rank 1
KocSistem asked on 08 Oct 2009, 07:38 AM

Hi,

I'm having a problem with radgrid and i couldn't find a general solution. Here is the scenario:

I have a search page that binds results to grid. pagesize=10. first query returns 11 elements so grid is 2 pages. i'm selecting second page then search again which returns 1 element. here is the problem, radgrid stuck at second page and i don't want to show "No records to display" message, i just want to reset page to 1. 

I can do it by:

protected void btnSearch_Click(object sender, EventArgs e)  
        {  
            grdBank.CurrentPageIndex = 0;  
            grdBank.Rebind();  
        } 

however, i'm using this grid in more than 100 pages which all have this problem. i don't want to put this code in every page. So i created my own custom pager as described here: http://www.telerik.com/help/aspnet-ajax/grdprogrammaticpagercustomization.html but this also has same problem. 

i tried to reset page by "e.Item.OwnerTableView.CurrentPageIndex = 0;" in "protected override void OnItemEvent(GridItemEventArgs e)" which works as expected but caused another problem that i can't go to page 3 which is also expected...

how can i solve it in pager? on which event should i reset page? 

Thanks

1 Answer, 1 is accepted

Sort by
0
KocSistem
Top achievements
Rank 1
answered on 12 Oct 2009, 01:37 PM

I have fixed the problem. Just put this code on your grid class

  protected override void OnDataBinding(EventArgs e)  
        {  
            DataSet ds = (DataSet)this.DataSource;  
            if (ds.Tables[0].Rows.Count < this.PageSize)  
            {  
                this.CurrentPageIndex = 0;  
            }  
            base.OnDataBinding(e);  
        } 

Tags
Grid
Asked by
KocSistem
Top achievements
Rank 1
Answers by
KocSistem
Top achievements
Rank 1
Share this question
or