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

Q3 2011 Grid - setting page size options

4 Answers 614 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 22 Jun 2013, 04:17 PM
We know we have set what the available page size options were on a Radgrid before, but we can't find our code for it. 2012 version had a Pagesizes property, but that's not there on Q3 2011. Anyone remember what the correct way to control page sizes in Q3 2011 was?

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 24 Jun 2013, 04:07 AM
Hi Jonathan,

You can set the page size in the client side as follows.

ASPX:
<telerik:RadGrid  ID="RadGrid1"   AllowPaging="true"  runat="server" PageSize="50">          
      <MasterTableView >
           <PagerStyle Mode="NextPrevAndNumeric" PageSizeLabelText="Page Size: " PageSizes="5,10,25,50,100,250" />
             <Columns>
               . . . . . . . . .
               . . . . . . . . .
            </Columns>
      </MasterTableView>         
</telerik:RadGrid>
 
OR you can pro-grammatically set it in the server side as follows.

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       if (e.Item is GridPagerItem)
       {
           RadComboBox PageSizeCombo = (RadComboBox)e.Item.FindControl("PageSizeComboBox");
  
           PageSizeCombo.Items.Clear();
           PageSizeCombo.Items.Add(new RadComboBoxItem("10"));
           PageSizeCombo.FindItemByText("10").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);
           PageSizeCombo.Items.Add(new RadComboBoxItem("20"));
           PageSizeCombo.FindItemByText("20").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);
           PageSizeCombo.Items.Add(new RadComboBoxItem("50"));
           PageSizeCombo.FindItemByText("50").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);
           PageSizeCombo.Items.Add(new RadComboBoxItem("100"));
           PageSizeCombo.FindItemByText("100").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);
           PageSizeCombo.Items.Add(new RadComboBoxItem("200"));
           PageSizeCombo.FindItemByText("200").Attributes.Add("ownerTableViewId", RadGrid1.MasterTableView.ClientID);
           PageSizeCombo.FindItemByText(e.Item.OwnerTableView.PageSize.ToString()).Selected = true;
       }
   }

ASPX:
<telerik:RadGrid ID="RadGrid1"  AllowPaging="True" PageSize="50" runat="server" OnItemDataBound="RadGrid1_ItemDataBound">
    <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</telerik:RadGrid>


Thanks,
Princy

0
Eon
Top achievements
Rank 1
answered on 05 Jan 2016, 02:16 PM
Thanks your aspx solution worked for me.
0
Jimmy
Top achievements
Rank 1
answered on 22 Jan 2018, 08:17 PM

Whenever I try to set the PageSize to something other than the default size in the grid the combobox values change but the number of items in the grid stays at the default.  

In my case my default page size is set to 25 but I want to change the grid to display 50 items and set the combo to 50.

 

See Below:

        protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridPagerItem)
            {
                RadComboBox PageSizeCombo = (RadComboBox)e.Item.FindControl("PageSizeComboBox");
                PageSizeCombo.Items.Clear();
                PageSizeCombo.Items.Add(new RadComboBoxItem("25"));
                PageSizeCombo.FindItemByText("25").Attributes.Add("ownerTableViewId", RadGrid2.MasterTableView.ClientID);
                PageSizeCombo.Items.Add(new RadComboBoxItem("50"));
                PageSizeCombo.FindItemByText("50").Attributes.Add("ownerTableViewId", RadGrid2.MasterTableView.ClientID);
                PageSizeCombo.Items.Add(new RadComboBoxItem("100"));
                PageSizeCombo.FindItemByText("100").Attributes.Add("ownerTableViewId", RadGrid2.MasterTableView.ClientID);
                PageSizeCombo.Items.Add(new RadComboBoxItem("200"));
                PageSizeCombo.FindItemByText("200").Attributes.Add("ownerTableViewId", RadGrid2.MasterTableView.ClientID);
                PageSizeCombo.Items.Add(new RadComboBoxItem("500"));
                PageSizeCombo.FindItemByText("500").Attributes.Add("ownerTableViewId", RadGrid2.MasterTableView.ClientID);
                
                int nSelectedIndex = 50;
                e.Item.OwnerTableView.PageSize = 50;
                switch (nSelectedIndex)
                {
                    case 1:
                        PageSizeCombo.FindItemByText("50").Selected = true;
                        e.Item.OwnerTableView.PageSize = 50;
                        break;
                    case 2:
                        PageSizeCombo.FindItemByText("100").Selected = true;
                        e.Item.OwnerTableView.PageSize = 100;
                        break;
                    case 3:
                        PageSizeCombo.FindItemByText("200").Selected = true;
                        e.Item.OwnerTableView.PageSize = 200;
                        break;
                    case 4:
                        PageSizeCombo.FindItemByText("300").Selected = true;
                        e.Item.OwnerTableView.PageSize = 300;
                        break;

                    default:
                        PageSizeCombo.FindItemByText("25").Selected = true;
                        e.Item.OwnerTableView.PageSize = 25;
                        break;
                }
                
            }
        }

 

            <telerik:RadGrid ID="RadGrid2" runat="server" AllowFilteringByColumn="true"  AllowAutomaticDeletes="True" AllowSorting="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False" ClientSettings-Resizing-AllowColumnResize="true" DataSourceID="SqlDataSource2" GridLines="Both" OnPreRender="RadGrid2_PreRender" PageSize="20" Skin="Office2007"  ShowFooter="true"  OnItemDataBound="RadGrid2_ItemDataBound">
                <ClientSettings>
                    <ClientEvents OnBatchEditCellValueChanged="ValueChangedRadGrid2" OnRowDeleted="OnDelete" OnCommand="OnCommand"/>
                </ClientSettings>
                <MasterTableView AutoGenerateColumns="False"  PageSize="25" CommandItemDisplay="Top" DataKeyNames="ID" EditMode="Batch" HorizontalAlign="NotSet" AllowMultiColumnSorting="False" AllowSorting="true">

0
Eyup
Telerik team
answered on 25 Jan 2018, 07:38 AM
Hello Jimmy,

This functionality is provided built-in by RadGrid - please use the PageSizes property to achieve this requirement:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/paging/overview

This will resolve the selection issue of the correct combo item.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Eon
Top achievements
Rank 1
Jimmy
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or