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

Change PageSizeComboBox items

7 Answers 268 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peichung
Top achievements
Rank 1
Peichung asked on 16 Apr 2009, 08:25 PM
Hi,

I would like to modify PageSizeComboBox to include total number of records in the grid, i.e. allow users to show all records on one page.  To achieve that, I first get the row counts by doing:

            // get total record counts  
            if (e.Item is GridFooterItem)  
            {  
                GridFooterItem footer = (GridFooterItem)e.Item;  
                ViewState["RecordCount"] = footer["IdCountInFooter"].Text.Replace("Count : """);  
            } 

and then I modified PageSizeComboBox by doing:

            // change Page Size Combobox  
            if (e.Item is GridPagerItem && ViewState["RecordCount"] != null)  
            {  
                GridPagerItem pager = (GridPagerItem)e.Item;  
                RadComboBox pageSizeComboBox = (RadComboBox)pager.FindControl("PageSizeComboBox");  
                PageSizeComboBox.Items.Add(new RadComboBoxItem(ViewState["RecordCount"].ToString(), ViewState["RecordCount"].ToString()));  
            } 

This does add the record count to PageSizeComboBox, however, when I select this added item in PageSizeComboBox, it doesn't update the grid.  So then I tried to change the last item in PageSizeComboBox:

            // change Page Size Combobox  
            if (e.Item is GridPagerItem && ViewState["RecordCount"] != null)  
            {  
                GridPagerItem pager = (GridPagerItem)e.Item;  
                RadComboBox pageSizeComboBox = (RadComboBox)pager.FindControl("PageSizeComboBox");  
                // added item doesn't fire
                // PageSizeComboBox.Items.Add(new RadComboBoxItem(ViewState["RecordCount"].ToString(), ViewState["RecordCount"].ToString()));  
                pageSizeComboBox.Items[3].Text = ViewState["RecordCount"].ToString();  
                pageSizeComboBox.Items[3].Value = ViewState["RecordCount"].ToString();  
            } 

This works.  However, if I did drag-n-drop grouping after setting the page size to RecordCount, the page size was automatically set to the first item in the combobox, rather than the last item.  Could you please advise the best way to update PageSizeComboBox items? 

Thanks,

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Apr 2009, 07:03 AM
Hi,

I tried changing the last item of the PageSize combobox and it is working well with Grouping as well. I am not sure what is happening on your end. In which event are you trying the above given code. I tried the code in the ItemCreated event. Here is the code which worked for me.

CS:
 
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridPagerItem) 
        { 
            GridPagerItem pager = (GridPagerItem)e.Item; 
 
            RadComboBox PageSizeComboBox = (RadComboBox)pager.FindControl("PageSizeComboBox"); 
            PageSizeComboBox.Items[3].Text = "80"
        } 
   } 


Shinu
0
Peichung
Top achievements
Rank 1
answered on 17 Apr 2009, 02:21 PM
I tried both ItemDataBound and ItemCreated, and none of them works. 

Let me further clarify my problem.  If I overwrite the third item's default value 50 with a new value, say 80, the page size combo does work in a sense that it sets the page size correctly at 80.  However, the combobox will have the first item selected, rather than the third item.  My observation is that inside the if (e.Item is GridPagerItem) code block, the modified page size 80 was not persisted over the Ajax round trip.  pageSizeComboBox.Items[3].Text and pageSizeComboBox.Items[3].Value are always set to the default value 50.  I am guessing that's why the selection was always the first item because the custom value 80 simply is not available in the combobox.

 

0
Pavlina
Telerik team
answered on 21 Apr 2009, 10:40 AM
Hello Peichung,

I am sending you a small runnable application with the implementation request by you. Give it a try and let me know if it works for you and if I am leaving something out.

Sincerely yours,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Peichung
Top achievements
Rank 1
answered on 21 Apr 2009, 05:04 PM
Hi Pavlina,

Thanks for the reply.  I added item.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID); but it doesn't help.  When I selected the newly added item in the page size combo, the first item in the combo was still selected, rather than the newly added item.  Thanks,

Peichung
0
Pavlina
Telerik team
answered on 23 Apr 2009, 02:48 PM
Hi Peichung,

I followed your scenario in order to replicate the issue but to no avail. At this point i will ask you to open a formal support ticket and send us a small working project which reproduces this erroneous behavior. Thus I could do all my best to help you further in resolving this matter.

Kind regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Brian Matuska
Top achievements
Rank 1
answered on 26 Jun 2009, 12:30 AM
a quick way to fix this is get the PageSize from e.Item.OwnerTableView.PageSize and set the ComboBox.

PageSizeComboBox.FindItemByText(e.Item.OwnerTableView.PageSize.ToString()).Selected = true

0
Pavlina
Telerik team
answered on 26 Jun 2009, 06:30 AM
Hello Brian,

Thank you for sharing your approach with us. Your cooperation is highly appreciated and I believe that it will help in resolving this problem.

Sincerely yours,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Peichung
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Peichung
Top achievements
Rank 1
Pavlina
Telerik team
Brian Matuska
Top achievements
Rank 1
Share this question
or