5

我的 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();

    }
4

3 回答 3

1

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

于 2012-10-07T11:49:22.177 回答
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
}
于 2012-08-07T12:57:44.013 回答
0

您需要定义“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()方法可能无法从那里获得。

于 2012-08-07T12:24:47.980 回答