This is a migrated thread and some comments may be shown as answers.

RadGrid Previous and Next buttons not working

2 Answers 299 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mahipal
Top achievements
Rank 1
Mahipal asked on 02 Aug 2011, 04:12 PM
Hi,
I have a RadGrid that displays the page numbers and the previous and Next buttions for paging functionality. The paging works when I click on the page number but not when I click on the previous/next buttons. The following is the skeleton of my code. Please suggest a solution to make this work.

It works fine if I take out the rebind() call in the page load event. However I need this to support other functionality. 

     protected void Page_Load(object sender, EventArgs e)
    {
        cboSelectReport.Attributes.Add("onchange", "DisplayNewReport();");
 
        string sqlString ="declare @startdate datetime; declare @enddate datetime;";
      sqlString = sqlString + "set @startdate = '" + dtpStart.SelectedDate.ToString() + "';";
      sqlString = sqlString + "set @enddate = '" + dtpEnd.SelectedDate.ToString() + "';";
       
   radgrid.Skin = "Outlook";
 
        ReportSource.SelectCommand = sqlString + ConfigurationManager.AppSettings["sqlcommand6"];
        ReportSource.DataBind();
 
        radgrid.Rebind();
    }

    public void radgrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        radgrid.DataSource = ReportSource;
    }

Thanks
Mahipal

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Aug 2011, 07:57 AM
Hello Mahipal,

I cannot reproduce the issue at my end. Make sure that you bind the grid entirely using NeedDataSource event which fires whenever paging, sorting, grouping etc occurs. Check the following help documentation and demo for more about this.
Advanced Data-binding (using NeedDataSource event).
Grid / Advanced Data Binding.

Thanks,
Princy.
0
Attila Antal
Telerik team
answered on 04 Oct 2023, 01:45 PM | edited on 04 Oct 2023, 01:51 PM

To everyone who is landing on this Forum thread with the same or similar problem, please note that rebinding in the Page Load without the condition if(!IsPostBack), will cause the Grid to re-create its structure every single time, thus losing the previous state.

To bind data to the Grid on the server side, use the following approaches:

Note: Regardless of the way you choose, never call the DataBind() method as this will break the Grid's expected behavior. To refresh the Grid, always use the Rebind() method.

DataBind() method is inherited from the generic ASP GridView Class, which is why it is available in the Telerik RadGrid, however, the Grid has its own ways of binding to data and we highly recommend using those.

Regards,
Attila Antal
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Tags
Grid
Asked by
Mahipal
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Attila Antal
Telerik team
Share this question
or