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

Grid Displays "No Records to display" on Page Changed Event

5 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Abdul
Top achievements
Rank 2
Abdul asked on 26 Nov 2010, 07:22 AM
Dear Team,
I am using datareader to bind data with grid. Works fine for first page but when a page index is changed or page size is changed grid displays no records...
it shows the new page or resized page correctly when I reload the page this is serverside code please tell me if i am missing something

protected void NeedDataSource()
{
    grd_report.Visible = true;
    if (IsPostBack == true && txt_todate.SelectedDate != null && txt_fromdate.SelectedDate != null)
    {
        String _todate = txt_todate.SelectedDate.Value.ToString("dd-MMM-yyyy");
        String _fromdate = txt_fromdate.SelectedDate.Value.ToString("dd-MMM-yyyy");
        obj_sales.initConnection();
        obj_sales.nwideTotalSalesSummary(_todate, _fromdate);
        grd_report.DataSource = obj_sales.getResults();
        grd_report.DataBind();
    }
}
protected void PageSizeChanged(object source, Telerik.Web.UI.GridPageSizeChangedEventArgs e)
{
    NeedDataSource();
    grd_report.Rebind();
}


        protected void NeedDataSource()
        {
            grd_report.Visible = true;
            if (IsPostBack == true && txt_todate.SelectedDate != null && txt_fromdate.SelectedDate != null)
            {
                String _todate = txt_todate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                String _fromdate = txt_fromdate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                obj_sales.initConnection();
                obj_sales.nwideTotalSalesSummary(_todate, _fromdate);
                grd_report.DataSource = obj_sales.getResults();
                grd_report.DataBind();
            }
        }
        protected void PageSizeChanged(object source, Telerik.Web.UI.GridPageSizeChangedEventArgs e)
        {
            NeedDataSource();
            grd_report.Rebind();
        }

        protected void NeedDataSource()
        {
            grd_report.Visible = true;
            if (IsPostBack == true && txt_todate.SelectedDate != null && txt_fromdate.SelectedDate != null)
            {
                String _todate = txt_todate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                String _fromdate = txt_fromdate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                obj_sales.initConnection();
                obj_sales.nwideTotalSalesSummary(_todate, _fromdate);
                grd_report.DataSource = obj_sales.getResults();
                grd_report.DataBind();
            }
        }
        protected void NeedDataSource()
        {
            grd_report.Visible = true;
            if (IsPostBack == true && txt_todate.SelectedDate != null && txt_fromdate.SelectedDate != null)
            {
                String _todate = txt_todate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                String _fromdate = txt_fromdate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                obj_sales.initConnection();
                obj_sales.nwideTotalSalesSummary(_todate, _fromdate);
                grd_report.DataSource = obj_sales.getResults();
                grd_report.DataBind();
            }
        }
        protected void NeedDataSource()
        {
            grd_report.Visible = true;
            if (IsPostBack == true && txt_todate.SelectedDate != null && txt_fromdate.SelectedDate != null)
            {
                String _todate = txt_todate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                String _fromdate = txt_fromdate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                obj_sales.initConnection();
                obj_sales.nwideTotalSalesSummary(_todate, _fromdate);
                grd_report.DataSource = obj_sales.getResults();
                grd_report.DataBind();
            }
        }
        protected void NeedDataSource()
        {
            grd_report.Visible = true;
            if (IsPostBack == true && txt_todate.SelectedDate != null && txt_fromdate.SelectedDate != null)
            {
                String _todate = txt_todate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                String _fromdate = txt_fromdate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                obj_sales.initConnection();
                obj_sales.nwideTotalSalesSummary(_todate, _fromdate);
                grd_report.DataSource = obj_sales.getResults();
                grd_report.DataBind();
            }
        }
        protected void NeedDataSource()
        {
  
protected void NeedDataSource()
{
    grd_report.Visible = true;
    if (IsPostBack == true && txt_todate.SelectedDate != null && txt_fromdate.SelectedDate != null)
    {
        String _todate = txt_todate.SelectedDate.Value.ToString("dd-MMM-yyyy");
        String _fromdate = txt_fromdate.SelectedDate.Value.ToString("dd-MMM-yyyy");
        obj_sales.initConnection();
        obj_sales.nwideTotalSalesSummary(_todate, _fromdate);
        grd_report.DataSource = obj_sales.getResults();
        grd_report.DataBind();
    }
}
protected void PageSizeChanged(object source, Telerik.Web.UI.GridPageSizeChangedEventArgs e)
{
    NeedDataSource();
    grd_report.Rebind();
}
         grd_report.Visible = true;
            if (IsPostBack == true && txt_todate.SelectedDate != null && txt_fromdate.SelectedDate != null)
            {
                String _todate = txt_todate.SelectedDate.Value.ToString("dd-MMM-yyyy");
  
protected void NeedDataSource()
{
    grd_report.Visible = true;
    if (IsPostBack == true && txt_todate.SelectedDate != null && txt_fromdate.SelectedDate != null)
    {
        String _todate = txt_todate.SelectedDate.Value.ToString("dd-MMM-yyyy");
        String _fromdate = txt_fromdate.SelectedDate.Value.ToString("dd-MMM-yyyy");
        obj_sales.initConnection();
        obj_sales.nwideTotalSalesSummary(_todate, _fromdate);
        grd_report.DataSource = obj_sales.getResults();
        grd_report.DataBind();
    }
}
 
protected void PageSizeChanged(object source, Telerik.Web.UI.GridPageSizeChangedEventArgs e)
{
    NeedDataSource();
    grd_report.Rebind();
}
             String _fromdate = txt_fromdate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                obj_sales.initConnection();
                obj_sales.nwideTotalSalesSummary(_todate, _fromdate);
                grd_report.DataSource = obj_sales.getResults();
                grd_report.DataBind();
            }
        }

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Nov 2010, 08:36 AM
 Hello Abdul,

I guess you are using simple databinding to populate the grid. Since you enabled paging in grid, a better option is using Advanced Data-binding (using NeedDataSource event) to bind the grid. And RadGrid fires the NeedDataSource event each time it needs to be bound to a data source

Please go through the following documentation for more on binding a grid using NeedDataSource event.

http://www.telerik.com/help/aspnet-ajax/grdadvanceddatabinding.html

Thanks,
Princy.
0
Abdul
Top achievements
Rank 2
answered on 26 Nov 2010, 08:58 AM
I am already using advanced binding

I have method for Need Data Source but when I insert break points on page event control does not go to the method however here is the method that i have

        protected void grd_report_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            grd_report.Visible = true;
            if (txt_todate.SelectedDate != null && txt_fromdate.SelectedDate != null && count == 0)
            {
                String _todate = txt_todate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                String _fromdate = txt_fromdate.SelectedDate.Value.ToString("dd-MMM-yyyy");
                obj_sales.initConnection();
                obj_sales.nwideTotalSalesSummary(_todate, _fromdate);
                grd_report.DataSource = obj_sales.getResults();
                count = 1;
            }
        }
 
<telerik:RadGrid ID="grd_report" Width="97%" AllowPaging="true" Visible = false
            runat="server" Gridlines="None" Skin="Windows7" AutoGenerateColumns="true"
            ShowStatusBar="true" AllowSorting="true" ShowGroupPanel="true"
              OnNeedDataSource="grd_report_NeedDataSource">
        </telerik:RadGrid>
0
Abdul
Top achievements
Rank 2
answered on 26 Nov 2010, 09:52 AM
it's not invoking onneeddatasource event on page change please tell me the reason
0
Pavlina
Telerik team
answered on 26 Nov 2010, 10:40 AM
Hi Abdul,

Have in mind that when the Visible property of the RadGrid control is set to False, the NeedDataSource event does not fire.When you change the Visible property of the grid to True, you must call the grid's Rebind method so that it can bind to its data. Review this help article for more information.

I hope this helps.

Best wishes,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Abdul
Top achievements
Rank 2
answered on 26 Nov 2010, 12:47 PM
Thanks it's Helpful 
Tags
Grid
Asked by
Abdul
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Abdul
Top achievements
Rank 2
Pavlina
Telerik team
Share this question
or