Grid pageSizer combobox lost selection

7 posts, 0 answers
  1. Hugo
    Hugo avatar
    5 posts
    Member since:
    Mar 2012

    Posted 09 Mar 2012 Link to this post

    I wanted more values inside the Grid pagesizer (instead of 10,20,50), so i wrote the following code (partly from the web)

            public static void ConfigurePageSizer(GridPagerItem pagerItem)
            {
                RadComboBox _pageSizeComboBox = (RadComboBox) pagerItem.FindControl("PageSizeComboBox");
                _pageSizeComboBox.Items.Clear();
                int[] _pageSize = new [] {10,20,50,100,250,500,750,1000};
                foreach (int _Size in _pageSize)
                {
                    RadComboBoxItem _item = new RadComboBoxItem();
                    _item.Text = _Size.ToString(CultureInfo.InvariantCulture);
                    _item.Value = _Size.ToString(CultureInfo.InvariantCulture);
                    _item.Attributes.Add("ownerTableViewId", pagerItem.OwnerTableView.ClientID);
                    _pageSizeComboBox.Items.Add(_item);    
                }
            }

    and then called it from : ....

            protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridPagerItem)
                {
                    GridHelper.ConfigurePageSizer((GridPagerItem)e.Item);
                }
            }

    But ... the problem is ...  the Grid page size combobox behaviour is now that is lost track of the current selected value, it always selects the first (10)

    Please advice and/or Tips 

    Kind regards,
          Hugo


  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 11 Mar 2012 Link to this post

    Hi Hugo,

    The forum thread below demonstrates how you can achieve the desired functionality:
    http://www.telerik.com/community/forums/aspnet-ajax/grid/changing-page-size-in-combo-box.aspx

    Greetings,
    Pavlina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Hugo
    Hugo avatar
    5 posts
    Member since:
    Mar 2012

    Posted 12 Mar 2012 Link to this post

    Hi Pavlina ,

    Like dexter (see the thread) the solution doesnot work for me, when is do a rebind the pageSizer combobox selects the default value.
    Why does the combobox loose selection when extending the values? That is wierd, man!
    In my opinion it should be very simply to extend the combox.

    Can you tell me how to extend the default page size combobox that works and interact with the radgrid, without doing a lot of coding myself, like keeping track of the curent selection myself by means of a session[selection]

    Kind regards,    
         Hugo
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 12 Mar 2012 Link to this post

    Hello Hugo,

    I am attaching a sample working project which handles the desired functionality. Please give it a try and let me know if it works for you and what is the difference in your case.

    Greetings,
    Pavlina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Hugo
    Hugo avatar
    5 posts
    Member since:
    Mar 2012

    Posted 21 Mar 2012 Link to this post

    The line of code that solve the problem  was:

     _pageSizeComboBox.Items.FindItemByValue(_grid.PageSize.ToString(CultureInfo.InvariantCulture)).Selected = true;

    So it seems RadGrid.pagesize keeps current page size (which is undocumented).
                
    So my final function :

            public static void ConfigurePageSizer(GridPagerItem pagerItem)
            {
                RadComboBox _pageSizeComboBox = (RadComboBox) pagerItem.FindControl("PageSizeComboBox");
                _pageSizeComboBox.Items.Clear();
                int[] _pageSize = new [] {10,20,50,100,250,500,750,1000};
                foreach (int _size in _pageSize)
                {
                    string _value = _size.ToString(CultureInfo.InvariantCulture);
                    RadComboBoxItem _item = new RadComboBoxItem(_value, _value);
                    _item.Attributes.Add("ownerTableViewId", pagerItem.OwnerTableView.ClientID);


                    if (_pageSizeComboBox.Items.FindItemByValue(_value) == null)
                    {
                        _pageSizeComboBox.Items.Add(_item);
                    }
                }
                RadGrid _grid = pagerItem.OwnerTableView.OwnerGrid;
                _pageSizeComboBox.Items.FindItemByValue(_grid.PageSize.ToString(CultureInfo.InvariantCulture)).Selected = true;
                _grid.Focus();
            }
  7. Spiros
    Spiros avatar
    15 posts
    Member since:
    May 2010

    Posted 10 Sep 2014 Link to this post

    Hi Shinu.
    I have a grid that is being filled from Need_DataSource event.
    In my grid i have 20 records , and when I select the (50) PageSizeComboBox  , the PageSizeComboBox
     is lost and i can not select any more.. Can you please tell me how i can fix this issue ?
    Thanks in advance.
    Spiros
  8. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 13 Sep 2014 Link to this post

    Hi,

    To make the pager always visible, even when the items are less than the selected pagesize, you should set AlwaysVisible property to true as shown below:
    <telerik:RadGrid  ID="RadGrid1"   AllowPaging="true"  runat="server" PageSize="10">        
          <MasterTableView >
               <PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="true" />
                ..................................

    Regards,
    Pavlina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017