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

[Solved] RadGrid PageSizeChanged Event for Detail Tables

5 Answers 426 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bryan Alfaro
Top achievements
Rank 1
Bryan Alfaro asked on 01 Feb 2010, 10:03 PM

Forum,

I have been unable to find a solution for PageSizeChanged Event for Detail Tables.  The below two code snippets show the RadGrid PageSizeChanged event functionality for Master Table PageSizeChange event.  I am using this functionality for User Profile settings and need the Detail Tables.  Let me know if there is a solution for this issue...

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="edsValuation" GridLines="None" 
        AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AllowFilteringByColumn="true" 
        OnPageSizeChanged="RadGrid1_PageSizeChanged"   
        PagerStyle-AlwaysVisible="true">  
</Format Code Block> 
 
 
protected void RadGrid1_PageSizeChanged(object source, GridPageSizeChangedEventArgs e)  
        {  
            Profile.LayoutProfile.StoreGridTableViewPageSize(RadGrid1.MasterTableView, e.NewPageSize);  
        } 

Thanks,
Bryan

Telerik.Web.UI - 2009.2.826.35

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Feb 2010, 10:43 AM
Hi,

You can access the pager item  RadComboBox in the ItemCreated event and fire the SelectedIndexChanged event  where you can access the changed value:

C#
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridPagerItem && e.Item.OwnerTableView.Name == "Reports"
        { 
            GridPagerItem pager = (GridPagerItem)e.Item; 
            RadComboBox cmbo = (RadComboBox)pager.FindControl("PageSizeComboBox"); 
            cmbo.AutoPostBack = true
            cmbo.SelectedIndexChanged +=new RadComboBoxSelectedIndexChangedEventHandler(cmbo_SelectedIndexChanged); 
        }  
   } 
 
 
 void cmbo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
      //Access value here 
    }  


Thanks,
Shinu
0
Bryan Alfaro
Top achievements
Rank 1
answered on 03 Feb 2010, 03:18 AM
Shinu,

I understand the approach you have given but this does not function with RadGrid properly.  

1.  Because we are intercepting the SelectedIndexChanged on the PagerItemComboBox, the grid does not make the Ajax call to put the new number of rows on the screen.  

2.  I tried setting the SelectedIndexChanged with the new user profile and it does not reflect in the number of rows.  this in turn does not work for the other detail tables of the same name.

I tried to put a rebind in the events but then the whole collapse/expand state gets lost and that's not feasible plus it still did not reflect the right number of rows.  Perhaps I need to set the Page Size at a different point in the Event structure so that the Detail Table reflects the right number of rows.

Updated Code Below:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridCommandItem) 
            { 
                e.Item.FindControl("InitInsertButton").Visible = false
                e.Item.FindControl("AddNewRecordButton").Visible = false
                 
            } 
 
            if (e.Item is GridPagerItem && e.Item.OwnerTableView.Name == "ValuationDetail") 
            { 
                GridPagerItem pager = (GridPagerItem)e.Item; 
                RadComboBox cmbo = (RadComboBox)pager.FindControl("PageSizeComboBox"); 
                cmbo.AutoPostBack = true
                cmbo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(VD_PSCB_SelectedIndexChanged); 
                Profile.LayoutProfile.RetrieveGridTableViewPageSize("ValuationDetail", cmbo); 
            } 
 
            if (e.Item is GridPagerItem && e.Item.OwnerTableView.Name == "ValuationDetailExposure") 
            { 
                GridPagerItem pager = (GridPagerItem)e.Item; 
                RadComboBox cmbo = (RadComboBox)pager.FindControl("PageSizeComboBox"); 
                cmbo.AutoPostBack = true
                cmbo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(VDE_PSCB_SelectedIndexChanged); 
                Profile.LayoutProfile.RetrieveGridTableViewPageSize("ValuationDetailExposure", cmbo); 
            } 
        } 

void VD_PSCB_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
        { 
            //Access value here 
            Console.WriteLine("New Page Size = " + e.Value.ToString()); 
            Profile.LayoutProfile.StoreGridTableViewPageSize("ValuationDetail", e.Value); 
        } 

void VDE_PSCB_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
        { 
            //Access value here  
            Console.WriteLine("New Page Size = " + e.Value.ToString()); 
            Profile.LayoutProfile.StoreGridTableViewPageSize("ValuationDetailExposure", e.Value); 
        } 

Thanks,
Bryan

0
Pavlina
Telerik team
answered on 04 Feb 2010, 04:45 PM
Hello Bryan,

For more information about how to retain the expanded/selected state for grid items in hierarchy upon a rebind command, please refer to this code library:
Retain expanded/selected state in hierarchy on rebind

Best wishes,
Pavlina
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Bryan Alfaro
Top achievements
Rank 1
answered on 05 Feb 2010, 02:58 PM
Forum,

Let me ask this specific question:

1.  How do I apply the same AJAX steps that a MasterTable Page Size Change Event performs in a Detail Table PagerItemComboBox.SelectedIndexChanged postback?

Thanks,
Bryan


0
Pavlina
Telerik team
answered on 10 Feb 2010, 04:10 PM
Hello Bryan,

In order to achieve the desired functionality, I suggest you review the following help article, which elaborates on this subject:
Traversing detail tables/items in Telerik RadGrid

Regards,
Pavlina
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
Grid
Asked by
Bryan Alfaro
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Bryan Alfaro
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or