【问题标题】:RadGrid Paging does not work fine after changing pageRadGrid 分页在更改页面后无法正常工作
【发布时间】:2012-08-04 10:14:19
【问题描述】:

我的 ASP.Net 应用程序中有一个 RadGrid,我已将 AllowPaging 设置为 True 并将 PageSize 设置为 10,现在它为每个 RadGridPage 加载 10 个项目,这是我想要的,但只要我按下下一页按钮(箭头看按钮)什么都没有加载,RadGrid 变空。 我怎样才能让它正常工作?

protected void Page_Load(object sender, EventArgs e)
    {
        PopulateGridOnLoad();
    }
private void PopulateGridOnLoad()
    {
        rgCustomers.DataSource = odsCustomers;
        // your datasource type
        rgCustomers.MasterTableView.VirtualItemCount = 28;
        //your datasource type total/count
        rgCustomers.CurrentPageIndex = rgCustomers.MasterTableView.CurrentPageIndex;
        rgCustomers.Rebind();

    }

protected void grdName_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {

        rgCustomers.DataSource = odsCustomers;
        // your datasource type
        rgCustomers.MasterTableView.VirtualItemCount = 28;
        //your datasource type total/count
        rgCustomers.CurrentPageIndex = rgCustomers.MasterTableView.CurrentPageIndex;
        //Donot rebind here
    }

    protected void btnLoad_Click(object sender, EventArgs e)
    {
        odsCustomers.SelectParameters["CustomerFullName"].DefaultValue = txtFullName.Text;
        odsCustomers.SelectParameters["CustomerMelliCode"].DefaultValue = txtMelliCode.Text;
        odsCustomers.SelectParameters["CustomerHomeAddress"].DefaultValue = txtHomeAddressPart.Text;
        odsCustomers.SelectParameters["CustomerWorkAddress"].DefaultValue = txtWorkAddressPart.Text;
        rgCustomers.DataSource = odsCustomers;
        rgCustomers.DataBind();

    }

【问题讨论】:

标签: c# asp.net telerik radgrid


【解决方案1】:

您必须在设计中设置网格的以下属性

 <telerik:RadGrid ID="grdName" 
             AllowPaging="True" 
             AllowCustomPaging="True"
             VirtualItemCount="0" PageSize="15" >

加载 vb.net 时填充网格

Private Sub PopulateGridOnLoad()

    grdName.DataSource = source ' your datasource type
    grdName.MasterTableView.VirtualItemCount = source.Total 'your datasource type total/count
    grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex
    grdName.Rebind()

End Sub

在加载 c#.net 时填充网格

private void PopulateGridOnLoad()
{
    grdName.DataSource = source;
    // your datasource type
    grdName.MasterTableView.VirtualItemCount = source.Total;
    //your datasource type total/count
    grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex;
    grdName.Rebind();

}

覆盖 NeedDatasource vb.net

 Protected Sub grdName_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdName.NeedDataSource

         grdName.DataSource = source ' your datasource type
         grdName.MasterTableView.VirtualItemCount = source.Total 'your datasource type total/count
         grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex
        'Donot rebind here
    End Sub

覆盖 NeedDatasource c#

protected void grdName_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{

    grdName.DataSource = source;
    // your datasource type
    grdName.MasterTableView.VirtualItemCount = source.Total;
    //your datasource type total/count
    grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex;
    //Donot rebind here
}

【讨论】:

  • 这有帮助,但我仍然无法使用 RadGrid 导航按钮,编号按钮工作但箭头按钮不工作
【解决方案2】:

找了很久才找到解决办法,问题涉及2个小问题:
1.我同时设置了 DataSource(在代码中)和 DataSourceID(属性),但它们不能很好地协同工作
2.我将 AllowPaging 和 AllowCustomPaging 都设置为 true,当它们都为 true 时,它​​们都不起作用:) 你知道的 Telerik 团队,但他们很棒,我在开玩笑

【讨论】:

    【解决方案3】:

    您需要定义“onNeedDataSource”radgrid 事件,您应该在其中重置网格的数据源。

      protected void RadGrid_NeedDataSource(object sender, EventArgs e)
          {
              IsNeedDataSource = true;
          }
    

    并且比在页面OnPreRender 事件中你应该这样做:

      protected override void OnPreRender(object sender, EventArgs e)
          {
               DriverLinksGrid.DataSource = value;
               DriverLinksGrid.DataBind();
          }
    

    我不放心,也许你可以在OnNeedDataSource 事件中直接绑定数据。但是DataBind() 方法可能无法从那里获得。

    【讨论】:

    • 那么 radgrid 为我做了什么?我怀疑这是一个很好的解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    • 1970-01-01
    • 1970-01-01
    • 2017-07-05
    • 2013-12-14
    • 2014-09-21
    相关资源
    最近更新 更多