2

I'm using a Telerik RadGrid with custom paging. My problem is that when I set the page size manually, the PageSizeChanged event gets fired and throws my code into an infinite loop. As a hack, I created a boolean that is set when the PageSizeChanged event gets fired. How do I set the page size on a RadGrid control without triggering the PageSizeChanged event?

private bool PageSizeChanged
{
    get { return Convert.ToBoolean(ViewState["PageSizeChanged"]); }
    set { ViewState["PageSizeChanged"] = value; }
}

protected void RadGrid1_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
{
    if (!PageSizeChanged)
    {
        PageSizeChanged = true;
        RadGrid1.PageSize = e.NewPageSize;
    }

    PageSizeChanged = false;                        
    RadGrid1.Rebind();
}

UPDATE: I have a solution that I like now. I ended up removing the event handler from the invocation list, setting the page size and then adding the event back to the invocation list.

protected void RadGrid1_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
{
    RadGrid1.PageSizeChanged -= RadGrid1_PageSizeChanged;
    RadGrid1.PageIndex = 0;
    RadGrid1.PageSize = e.NewPageSize;
    RadGrid1.Rebind();
    RadGrid1.PageSizeChanged += RadGrid1_PageSizeChanged;
}

2 Answers 2

7

try this-

protected void RadGrid1_PageSizeChanged(object source, GridPageSizeChangedEventArgs e) 
    {                
       RadGrid1.PageSizeChanged-=new GridPageSizeChangedEventHandler(RadGrid1_PageSizeChanged);
       RadGrid1.PageSize =  e.NewPageSize;

      RadGrid1.PageSizeChanged += new GridPageSizeChangedEventHandler(RadGrid1_PageSizeChanged);

      RebindGrid();
    }
0
2

Remove the RadGrid1_PageSizeChanged, and assing the page size as -

RadGrid1.MasterTableView.PageSize = CustomerPageSize;
2
  • Thanks for your suggestion. It led to my update and now I have working code.
    – Halcyon
    May 21, 2012 at 21:40
  • I do not understand why you have RadGrid1_PageSizeChanged. Normally you do not need to assign PageSize inside PageSizeChanged event explicitly. It's why you encounter infinite loop.
    – Win
    May 21, 2012 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.