5

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

    }
Mahdi Tahsildari
  • 13,065
  • 14
  • 55
  • 94

3 Answers3

1

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
}
Pravin Pawar
  • 2,559
  • 3
  • 34
  • 40
1

After a long time I found the solution, the problem involved 2 minor issues :
1.I had both DataSource (in code) and DataSourceID (property) set and they didn't work together well
2.I had both AllowPaging and AllowCustomPaging set to true, when they are both true neither works :) that's the telerik team you know, but they are great I was kidding

Mahdi Tahsildari
  • 13,065
  • 14
  • 55
  • 94
0

You need to define the "onNeedDataSource" radgrid event where you shoud reset the datasource of your grid.

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

and than in page OnPreRender event you shoul do smth like:

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

I'm not shure, maybe you can bind data right in OnNeedDataSource event. But the DataBind() method may be not not available from there.

Phist
  • 68
  • 4