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

RadGrid Pagesize always 10 in NeedDataSource (Server Control)

1 Answer 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 26 Mar 2014, 06:03 PM
Hi,

I have a radGrid.  The data populated is very expensive to gather, so I have opted to collect only the data shown on the current page of the grid and set the virtual count to a select COUNT(*) ...etc. which works fine when I have the radGrid on a webpage.  

In the NeedDatasounrce event, I simply get the radGrid.PageSize & radGrid.CurrentPageIndex and use these to figure out the set to return... this all works ok in a web page.

However, if I use the same grid in a server control (built in CreateChildControls()) the page size is always 10, even when I jump from 10 to 20 to 50, each time in (needdatasource event) code it is 10.  Viewstate is enabled for this grid, could it be that the viewstate has not loaded for this grid at this point?  If so , any reason why not for server control, but OK on the aspx webpage?...(differences in event orders??)  

Is there anything I can do to get this pagesize value at the radGrid_needdatasource event for my server control?

ps - This new page value is available by the time we get to the pre_render event... and the PageSize changed event fires after the needdatasource event, so these eventargs are too late to be used in the datasource.

Thanks in advance

1 Answer, 1 is accepted

Sort by
0
Craig
Top achievements
Rank 1
answered on 28 Mar 2014, 12:05 PM
Well, the best method I could devise to resolve this was rebinding on thePageIndexChanged and the PageSizeChanged events and saving the pageSize and currentPageIndex in session ... not ideal as the first time the needDataSource event fires, it uses the wrong values...

In these events I simply set the datrasource again and rebind like so...

        void _radGrid_PageIndexChanged(object sender, GridPageChangedEventArgs e)
        {
            System.Web.HttpContext.Current.Session["currPageIndex"] = e.NewPageIndex; //Save nee page number is session variable... Zero based
            _radGrid.DataSource = LoadGridData();
            _radGrid.Rebind();
        }

        void _radGrid_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
        {
            System.Web.HttpContext.Current.Session["currPageSize"] = e.NewPageSize;
            System.Web.HttpContext.Current.Session["currPageIndex"] = 1; // Go back to first page
            _radGrid.DataSource = LoadGridData();
            _radGrid.Rebind();
}


Tags
Grid
Asked by
Craig
Top achievements
Rank 1
Answers by
Craig
Top achievements
Rank 1
Share this question
or