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

RadGrid PageSize CurrentPageIndex

3 Answers 756 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cliff Akers
Top achievements
Rank 1
Cliff Akers asked on 05 Apr 2010, 04:05 PM

Hello All,

I have a web application that uses several of the Telerik controls. The default page of the web application contains a tabstrip control and a radgrid control. The user can search for persons or employers which will cause a new tab to be instantiated for each new entity.
The radgrid is rendered with the correct data based on the tab that is selected.

The issue that I am experiencing occurs if I try to update pagesize and currentpageindex. The pagesize and currentpageindex are being saved in the session for each tab instance. I am attempting to update the radgrid during the prerender event with the correct pagesize and currentpageindex. Attempting to udpate in the prerender event does not change the pagesize or currentpageindex. What am I missing here?

Thanks for any help that you might be able to offer.

Regards,
Cliff

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 06 Apr 2010, 06:04 AM
Hi Cliff,

For achieving desired result you need to call the Rebind() method after setting the correct PageSize and CurrentPageIndex. Check out the following code:

C#:

protected
 void RadGrid1_PreRender(object sender, EventArgs e) 
    RadGrid1.PageSize = 3; 
    RadGrid1.CurrentPageIndex = 2; 
    RadGrid1.MasterTableView.Rebind(); 

Regards
Princy.
0
Cliff Akers
Top achievements
Rank 1
answered on 06 Apr 2010, 04:06 PM
I tried changing the pagesize and currentpageindex in the PreRender event as described below. The grid is still not updating properly with the correct pagesize or currentpageindex. Here is the code for the PreRender event:

Private Sub dgDocuments_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles dgDocuments.PreRender 
        If Not String.IsNullOrEmpty(dgDocuments.MasterTableView.FilterExpression) Then 
            dgDocuments.CachedFilterExpression = dgDocuments.MasterTableView.FilterExpression 
        End If 
 
        If Not Session("Clear_dgDocumentsSettings") = True Then 
            'MLM - SaveSetting MUST be called from PreRender phase. 
            Session(dgDocuments.GridTabID + "dgDocumentsSettings") = dgDocuments.SaveSettings() 
        End If 
        If Not Session(dgDocuments.GridTabID + "PageSize"Is Nothing Then 
            dgDocuments.PageSize = Session(dgDocuments.GridTabID + "PageSize"
            dgDocuments.MasterTableView.Rebind() 
        End If 
        Session("Clear_dgDocumentsSettings") = False 
End Sub 

I have stepped through the code and the third conditional statement is being executed. However, I am seeing no changes in the pagesize or currentpageindex for the grid. Do I need to explicitly call the pagesizechanged event? If I change the page size using the radgrid control gui, then the pagesize is successfully changed. The problem is there could be multiple tabs opened each with their own corresponding settings saved in the session. Whatever I manually change the pagesize to using the gui is persisted for all tabs.
0
Cliff Akers
Top achievements
Rank 1
answered on 06 Apr 2010, 05:38 PM
Hello All,

First off, thanks to Princy for your input on this issue and getting me headed in the right direction. It turns out that the snippet of code that you provided was very close to being correct. If you change the code to the following, all my problems are solved:

 
protected void RadGrid1_PreRender(object sender, EventArgs e)  
{  
    RadGrid1.MasterTableView.PageSize = 3;  
    RadGrid1.MasterTableView.CurrentPageIndex = 2;  
    RadGrid1.MasterTableView.Rebind();  
}  

Apparently, the issue is due to the PageSizeChanged event not being raised when the PageSize is changed programmatically. The following line of code will cause the PageSizeChanged event to be raised:

RadGrid1.MasterTableView.CurrentPageIndex = 2; 

While this line of code will NOT cause the PageSizeChanged event to be raised:

RadGrid1.CurrentPageIndex = 2; 

There is a thread that may be related to this topic:

Regards,
Cliff  
Tags
Grid
Asked by
Cliff Akers
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Cliff Akers
Top achievements
Rank 1
Share this question
or