2

我正在使用带有自定义分页的 Telerik RadGrid。我的问题是,当我手动设置页面大小时,PageSizeChanged 事件被触发并将我的代码抛出一个无限循环。作为 hack,我创建了一个在 PageSizeChanged 事件被触发时设置的布尔值。如何在 RadGrid 控件上设置页面大小而不触发 PageSizeChanged 事件?

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();
}

更新:我现在有一个我喜欢的解决方案。我最终从调用列表中删除了事件处理程序,设置了页面大小,然后将事件添加回调用列表。

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;
}
4

2 回答 2

7

尝试这个-

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();
    }
于 2012-05-23T07:09:55.433 回答
2

删除 RadGrid1_PageSizeChanged,并将页面大小设置为 -

RadGrid1.MasterTableView.PageSize = CustomerPageSize;
于 2012-05-21T21:03:20.700 回答