加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 更改页面后,RadGrid分页无法正常工作

发布时间:2020-12-15 17:28:09 所属栏目:百科 来源:网络整理
导读:我的ASP.Net应用程序中有一个RadGrid,我将AllowPaging设置为True,PageSize设置为10,现在每个RadGridPage加载10个项目,这就是我想要的,但是只要按下Next Page按钮(箭头看按钮)没有任何负载,RadGrid变空. 我怎样才能让它正常工作? protected void Page_Load(o
我的ASP.Net应用程序中有一个RadGrid,我将AllowPaging设置为True,PageSize设置为10,现在每个RadGridPage加载10个项目,这就是我想要的,但是只要按下Next Page按钮(箭头看按钮)没有任何负载,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();

    }

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读