RadGrid Paging does not work fine after changing page

Mahdi Tahsildari picture Mahdi Tahsildari · Aug 7, 2012 · Viewed 21.3k times · Source

I have a RadGrid in my ASP.Net app and I have set the AllowPaging to True and PageSize to 10, now it load 10 items per RadGridPage which is what I wanted, but as soon as I press Next Page button (Arrow look button) nothing loads and RadGrid gets empty. How can I make it work normal?

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

    }

Answer

Pravin Pawar picture Pravin Pawar · Aug 7, 2012

You will have to set up following attributes of the grid in design

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

Populate grid on load 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

Populate grid on load 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();

}

Override 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

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