RadGrid with "ALL" option in the page size combo box

36 posts, 0 answers
  1. Asok
    Asok avatar
    9 posts
    Member since:
    May 2009

    Posted 26 Feb 2011 Link to this post

    Hello,

    I want to add "ALL" option to my RadGrid Page Size combo. I want the options 50,100,150,ALL. I know we can customize the page size option. However when I am adding the "ALL" option, it is returning an error "Input string was not in correct format". The requirement is when selecting the "ALL" option I want to show all the records in the Grid.

    Please advise!

    Thank you,
    Asok
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Feb 2011 Link to this post

    Hello Asok,

    I have tried the same scenario and that worked fine at my end. Here I am pasting my code please make a double check with your code.
    C#:
    protected void rad_ItemCreated(object sender, GridItemEventArgs e)
        {
        if (e.Item is  GridPagerItem)
            {
                GridPagerItem pager = (GridPagerItem)e.Item;
                RadComboBox PageSizeComboBox = (RadComboBox)pager.FindControl("PageSizeComboBox");
                RadComboBoxItem ComboItem = new RadComboBoxItem("All");
                PageSizeComboBox.Items.Insert(0, ComboItem);
                PageSizeComboBox.AutoPostBack = true;
                PageSizeComboBox.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(PageSizeComboBox_SelectedIndexChanged);
            }
        }
    void PageSizeComboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
       {
           //Handle the event
       }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. levs
    levs avatar
    6 posts
    Member since:
    Jul 2011

    Posted 20 Jul 2011 Link to this post

    Hi Shinu,

    For your sample, the PageSizeComboBox_SelectedIndexChanged is not getting fired.
    Any suggestion?

    Thanks,

    -levs
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Jul 2011 Link to this post

    Hello Levs,

    I tried to recreate the issue but no aval. I hope the following approach helps you to solve the issue.
    How to Add "Show All" option in RadGrid Paging.

    Thanks,
    Shinu.
  6. Stan
    Stan avatar
    36 posts
    Member since:
    Feb 2011

    Posted 17 Aug 2011 Link to this post

    Shinu:

    Your solution
    protected void LineItems_ItemEvent(object sender, GridItemEventArgs e)
            {
                if (e.EventInfo is GridInitializePagerItem)
                {
                    TotalItemCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount;
                }
            }
      
    protected void LineItems_ItemCreated(object sender, GridItemEventArgs e)
           {
                    if (e.Item is GridPagerItem)
                    {
                        GridPagerItem pagerItem = (GridPagerItem)e.Item;
                        RadComboBox pageSizeComboBox = (RadComboBox)pagerItem.FindControl("PageSizeComboBox");
                        RadComboBoxItem allItem = new RadComboBoxItem();
                        allItem = new RadComboBoxItem("All", TotalItemCount.ToString());
                        allItem.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID);
                        pageSizeComboBox.Items.Add(allItem);
                    }
          }
    works, but there is one problem with it. When page size is changed to "All" the grid displays all the items, but the pager combox box value is 10 and not "All". Available page sizes in the combo box are 10, 20, 30, 50 and All. Changing page size to any item except All retains the value, but All does not.

    Can you tell how to fix it?

    Thanks,
    -Stan
  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 22 Aug 2011 Link to this post

    Hello Stan,

     Please try to set the current pagesize as the selected value like this:
    pageSizeComboBox .Items.FindItemByValue(grid.PageSize.ToString()).Selected = true;



    All the best,
    Maria Ilieva
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  8. B
    B avatar
    5 posts
    Member since:
    Jan 2009

    Posted 07 Oct 2011 Link to this post

    I have the same problem, implemented the solution as posted and have one usability issue:
    --> On page load, the pager combo box shows '10, 20, 50, All'. Great!
    --> On selection of 'All' the pager adds an additional item and selects it.. '10, 20, 50, 68, All'
    --> On my Grid, there is a RadComboBox Filter that I use to filter the results by state. So, after a user 'views all' for say, 'AK', the pager box says '68' instead of 'All', which means when I select another state (i.e. 'AL') I see the first 68 results, instead of seeing 'All'.

    To make this make more sense, let me put it this way:

    Using the provided code, when I select the 'All' option, an additional list item is added to the RadComboBox 'PageSizeComboBox', with a value of the # of records for the current data source. So instead of the 'All' option being selected, a new list item is automatically added. This is not the behavior we want, or expect.

    What I want, is simply, an 'All' option, that when selected, persists as the selected option, and continues to return all results, even after the filter has been changed.

    Code I'm using is:
    private int TotalItemCount;
    protected void rgRecords_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridPagerItem)
        {
            GridPagerItem pagerItem = (GridPagerItem)e.Item;
            RadComboBox PageSizeCombo = (RadComboBox)pagerItem.FindControl("PageSizeComboBox");
            RadComboBoxItem item1 = new RadComboBoxItem();
            item1 = new RadComboBoxItem("All", TotalItemCount.ToString());
            item1.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID);
            PageSizeCombo.Items.Add(item1);
            PageSizeCombo.Items.FindItemByValue(rgRecords.PageSize.ToString()).Selected = true;
        }
    }
     
    protected void rgRecords_ItemEvent(object sender, GridItemEventArgs e)
    {
        if (e.EventInfo is GridInitializePagerItem)
        {
            TotalItemCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount;
        }
    }
  9. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 12 Oct 2011 Link to this post

    Hello,

    Try to set the pagesize for "All" to int.MaxValue as described in the forum thread below and verify of this helps:
    http://www.telerik.com/community/forums/aspnet-ajax/grid/show-all-option-on-the-pager.aspx

    Greetings,
    Maria Ilieva
    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
  10. B
    B avatar
    5 posts
    Member since:
    Jan 2009

    Posted 12 Oct 2011 Link to this post

    Hi Maria,

    Great. Now the only problem left is that, after selecting the 'All' option, the combo box adds a new list item, with the value '2147483647'. Is there not a way for an user to select 'All' and for that option to stay persisted through page use? I do not understand why the option 'All' when selected, always adds a new list item to the drop down, instead of staying selected.

    Thanks, -B
  11. B
    B avatar
    5 posts
    Member since:
    Jan 2009

    Posted 12 Oct 2011 Link to this post

    Does Telerik even have a solution? Why are we paying the subscription price, when we can't even 'show all records' is a major concern and question for me. The question is, if I have to write my own pager for something as simple as 'Show All Records' why am I even using a Telerik product to begin with? Why does Telerik have a GRID control with no method or otherwise answer on how to 'Show All Records'?

    If anybody does have an answer, or anyone representing Telerik that'd like to keep a current and paid subscriber, sure I'm all ears. However, I only ask that you only reply with a SOLUTION to this problem since I don't have time to keep trying things that don't work.

    Again, my problem is:

    I have a select box with 10, 20, 50 and [All]. I am adding the all option by using this code:
    protected void rgRecords_ItemCreated(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridPagerItem)
                {
                    RadComboBox combo = (e.Item as GridPagerItem).FindControl("PageSizeComboBox") as RadComboBox;
                    RadComboBoxItem item = new RadComboBoxItem("All", int.MaxValue.ToString());
                    item.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID);
                    combo.Items.Add(item);
                    combo.Items.FindItemByValue(rgRecords.PageSize.ToString()).Selected = true;
                }
            }

      In any web browser (FireFox, Opera, IE, Chrome), when the user selects the 'All' option, a 5th option is added to the drop down list with a value of '2147483647' (int.MaxValue). Not what we want. We want the user to select 'All' and all records to show, and that the drop down list remains unmodified... So when the user selects 'All', the drop down list should contain '10, 20, 50, All' and 'All' should stay selected. Please, no more examples that create page artifacts.

    Thanks! -B
  12. B
    B avatar
    5 posts
    Member since:
    Jan 2009

    Posted 12 Oct 2011 Link to this post

    Maybe, someone at Telerik could create a new, sample / test solution, with Visual Studio 2010, using the latest stable release of the Telerik RadGrid, and SHOW us that an 'All' option can be created and used without creating page artifacts!

    Please, begging for a sample project with a RadGrid, that has an 'All' option, that when selected stays selected.
  13. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 17 Oct 2011 Link to this post

    Hi,

    Find attached a sample runnable application which works correctly in all browsers wilt the latest official Q2 2011 SP1 release. Test it on your side and let me know if it works for you.

    Best wishes,
    Maria Ilieva
    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
  14. B
    B avatar
    5 posts
    Member since:
    Jan 2009

    Posted 21 Oct 2011 Link to this post

    This is the code that works (does not leave a page artifact).

    if (e.Item is GridPagerItem)
                {
                    RadComboBox combo = (e.Item as GridPagerItem).FindControl("PageSizeComboBox") as RadComboBox;
                    RadComboBoxItem item = new RadComboBoxItem("All", int.MaxValue.ToString());
                    item.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID);
                    combo.Items.Add(item);
                    if (rgRecords.PageSize == int.MaxValue)
                    {
                        combo.Items.FindItemByText("All").Selected = true;
                    }
                    else
                    {
                        combo.Items.FindItemByValue(rgRecords.PageSize.ToString()).Selected = true;
                    }
                    RadComboBoxItem extraItem = combo.Items.FindItemByText(int.MaxValue.ToString());
                    if (extraItem != null)
                    {
                        combo.Items.Remove(extraItem);
                    }
                }
  15. christian
    christian avatar
    7 posts
    Member since:
    Jul 2011

    Posted 21 Nov 2011 Link to this post

    works great indeed!

    the only thing I added was setting the pager style of the MasterTableView to "allways visible", otherwise the pager disappears as soon as you select "all".
  16. Pramit Agrawal
    Pramit Agrawal avatar
    4 posts
    Member since:
    Jun 2012

    Posted 02 Jul 2012 Link to this post

    Hi,

    When I select option All, pager control display "8 items in 0 pages". Pager control should display "8 items in 1 pages".
  17. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 02 Jul 2012 Link to this post

  18. kahuna
    kahuna avatar
    6 posts
    Member since:
    Jun 2007

    Posted 02 Jul 2012 Link to this post

    Hi Pramit... 

    I.E. 1 Pages is not proper English, it should be 1 Page. To fix your issue, use Page_PreRender (if you only have a BOTTOM pager, you do not have to do this in the Page_PreRender event. However, if you have both a TOP and BOTTOM pager, then this code must be here, since when the TOP pager is created in the RadGrid_ItemCreated event, it does not know how many items there are in the grid. So you MUST do this after the grid has been created.)

    protected void Page_PreRender(object sender, EventArgs e)
            {
                //Fix page count in pager
                if (rgRecords.MasterTableView.Items.Count == 0)
                {
                    rgRecords.MasterTableView.PagerStyle.PagerTextFormat = "{4}<strong>0</strong> items in <strong>0</strong> pages";
                }
                else if (rgRecords.MasterTableView.Items.Count == 1)
                {
                    rgRecords.MasterTableView.PagerStyle.PagerTextFormat = "{4}<strong>{5}</strong> item in <strong>1</strong> page";
                }
                else if (rgRecords.PageSize == int.MaxValue || rgRecords.PageCount <= 1)
                {
                    rgRecords.MasterTableView.PagerStyle.PagerTextFormat = "{4}<strong>{5}</strong> items in <strong>1</strong> page";
                }
                else
                {
                    rgRecords.MasterTableView.PagerStyle.PagerTextFormat = "{4}<strong>{5}</strong> items in <strong>{1}</strong> pages";
                }
                rgRecords.Rebind(); //Must rebind for changes to take effect.
            }
  19. Pramit Agrawal
    Pramit Agrawal avatar
    4 posts
    Member since:
    Jun 2012

    Posted 03 Jul 2012 Link to this post

    HI Kahuna,

    Thanks for your reply.

    I have only Bottom pager. Where I should right code to show correct english in pager.

    Thanks
    Pramit
  20. Pramit Agrawal
    Pramit Agrawal avatar
    4 posts
    Member since:
    Jun 2012

    Posted 03 Jul 2012 Link to this post

    Hi Jayesh,

    After adding the item into combobox it should be selected. You have one line missing in your code.

    pageSizeCombo.FindItemByValue(e.Item.OwnerTableView.PageSize.ToString()).Selected = true;

     

    Initially I have the same code then I change my code to use int.MaxValue for "All" option. Problem in this code is, When "All" option is selected in pager and user Add/Delete any record in grid. It will give to runtime error. e.Item.OwnerTableView.PageSize is not increase/decrease and above line thru runtime error.

    I solve this issue by adding if statement

    if (rgRecords.PageSize == int.MaxValue)

    {
    pageSizeCombo.Items.FindItemByText("All").Selected = true;
    }
    else
    {
    pageSizeCombo.Items.FindItemByValue(e.Item.OwnerTableView.PageSize.ToString()).Selected = true;
    }


    But Now problem is, When I add any item in grid, It Add item in next page, despite "All" option is selected in PagerComboBox.

    Thanks
    Pramit

  21. kahuna
    kahuna avatar
    6 posts
    Member since:
    Jun 2007

    Posted 03 Jul 2012 Link to this post

    Hi Pramit,

    Unless you are opposed to using Page_PreRender, I would still use that same method. Full code listing to add the All option, and to have the pager display the correct tense for # of items and # of pages:

    ASPX:

    <telerik:RadGrid ID="rgRecords" runat="server" AllowSorting="true" AllowPaging="true" AutoGenerateColumns="false" Width="100%" PageSize="20" Skin="WebBlue" OnNeedDataSource="rgRecords_NeedDataSource" OnItemCreated="rgRecords_ItemCreated">
                <MasterTableView CommandItemDisplay="None">
                    <NoRecordsTemplate>
      
                    </NoRecordsTemplate>
                    <Columns>
      
                    </Columns>
                    <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" Position="TopAndBottom" />
                </MasterTableView>
            </telerik:RadGrid>

    C#:

    protected void Page_Load(object sender, EventArgs e)
            {
                Page.PreRender += new EventHandler(Page_PreRender);
            }
            protected void Page_PreRender(object sender, EventArgs e)
            {
                //Fix page count in pager
                if (rgRecords.MasterTableView.Items.Count == 0)
                {
                    rgRecords.MasterTableView.PagerStyle.PagerTextFormat = "{4}<strong>0</strong> items in <strong>0</strong> pages";
                }
                else if (rgRecords.MasterTableView.Items.Count == 1)
                {
                    rgRecords.MasterTableView.PagerStyle.PagerTextFormat = "{4}<strong>{5}</strong> item in <strong>1</strong> page";
                }
                else if (rgRecords.PageSize == int.MaxValue || rgRecords.PageCount <= 1)
                {
                    rgRecords.MasterTableView.PagerStyle.PagerTextFormat = "{4}<strong>{5}</strong> items in <strong>1</strong> page";
                }
                else
                {
                    rgRecords.MasterTableView.PagerStyle.PagerTextFormat = "{4}<strong>{5}</strong> items in <strong>{1}</strong> pages";
                }
                rgRecords.Rebind(); //Must rebind for changes to take effect.
            }
            protected void rgRecords_ItemCreated(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridPagerItem)
                {
                    GridPagerItem gpi = e.Item as GridPagerItem;
      
                    //Give pager drop down an 'All' option.
                    RadComboBox combo = gpi.FindControl("PageSizeComboBox") as RadComboBox;
                    if (combo != null)
                    {
                        RadComboBoxItem item = new RadComboBoxItem("All", int.MaxValue.ToString());
                        item.Attributes.Add("ownerTableViewId", gpi.OwnerTableView.ClientID);
                        combo.Items.Add(item);
                        if (rgRecords.PageSize == int.MaxValue) { combo.Items.FindItemByText("All").Selected = true; }
                        else { combo.Items.FindItemByValue(rgRecords.PageSize.ToString()).Selected = true; }
                        if (combo.Items.FindItemByText(int.MaxValue.ToString()) != null) { combo.Items.Remove(combo.Items.FindItemByText(int.MaxValue.ToString())); }
                    }
                }
            }
            protected void rgRecords_NeedDataSource(object sender, EventArgs e)
            {
    //Set your data source here.
            }



  22. Strang
    Strang avatar
    1 posts
    Member since:
    Aug 2006

    Posted 12 Jul 2012 Link to this post

    Hi Pramit,

    There is pretty simple solution to have always "1 pages of 1" for "All" option: use (int.MaxValue-1) instead of (int.MaxValue).
    It works at least in Telerik RadControls ASP.NET AJAX 2010Q3.
    RadComboBoxItem item = new RadComboBoxItem("All", (int.MaxValue-1).ToString());

    WBR,
    Sergey Arkhipov.
  23. Kevin
    Kevin avatar
    26 posts
    Member since:
    Mar 2012

    Posted 24 Aug 2012 Link to this post

    I've been using the solution that was supplied in the zip file attached by Maria Ilieva in the thread.  It has worked pretty well for me but there's a bug with it that I've been unable to work through.  Take Maria's solution exactly as is but add CommandItemDisplay="Bottom" to the MasterTableView and then add a CommandItemTemplate for insert like this 
    <CommandItemTemplate>
       <div>
          <asp:Button CommandName="InitInsert" CssClass="rgAdd" RunAt="Server"/>
          <asp:LinkButton CommandName="InitInsert" RunAt="Server">New User</asp:LinkButton>
       </div>
    </CommandItemTemplate>

    Load the page, select "All" for the PageSize, then click the insert button.  I get an error "Specified argument was out of the range of valid values." in the call stack at GridTableView::set_CurrentPageIndex(), GridTableView::InsertItem().

    Is there a solution for this?

    Thanks,
    Kevin
  24. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 29 Aug 2012 Link to this post

    Hi Kevin,

    Find attached the modified version of the application which works correctly for the insert item scenario you are implementing. Test it on your end and let me know if it covers your requirements.

    Greetings,
    Maria Ilieva
    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.
  25. Rohan
    Rohan avatar
    94 posts
    Member since:
    Jul 2012

    Posted 11 Oct 2012 Link to this post

    Hi Maria llieva,
    i have same requirement for rad grid and i am referencing  your code ="AllPaging-modified.zip" to add "All" option to page size drop down.
    i am able to do this but when i am clicking to Add new record button it gives me exception
    exception was-
    Specified argument was out of the range of valid values. Parameter name: value
    and source of exception
    Telerik.Web.UI.GridTableView.set_CurrentPageIndex
  26. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 16 Oct 2012 Link to this post

    Hello Rohan,

    I tested again the previously provided application and was not bale to replicate the error you are facing. See the movie below which shows my local tests and let me know if I'm missing something:
    http://screencast.com/t/7bWDYiyQWL

    Please do let me know if you have applied any modification on the application so that the issue starts to appear.

    Regards,
    Maria Ilieva
    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.
  27. Rohan
    Rohan avatar
    94 posts
    Member since:
    Jul 2012

    Posted 16 Oct 2012 Link to this post

    Hi Maria llieva,

    Thanks for replay ...

    I solve issues with page size "all" option by setting GridInsertItemPageIndexAction.ShowItemOnFirstPage.
  28. Rohan
    Rohan avatar
    94 posts
    Member since:
    Jul 2012

    Posted 20 Oct 2012 Link to this post

    Hi Maria llieva,
    Thanks for replay ,
    now i am facing the new issues with delete - when i am fire delete command of radgrid it gives same exception

    exception was-
    Specified argument was out of the range of valid values. Parameter name: value
    and source of exception
    Telerik.Web.UI.GridTableView.set_CurrentPageIndex
  29. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 25 Oct 2012 Link to this post

    Hi Rohan,

    I further tested the previously provided project but I'm not able to replicate the mentioned errors on my end. Could I kindly ask you to open  regular support ticket and send us your version of the application so we could test is locally and advise you on the problem?

    Greetings,
    Maria Ilieva
    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.
  30. Rohan
    Rohan avatar
    94 posts
    Member since:
    Jul 2012

    Posted 01 Nov 2012 Link to this post

     Hi Maria,

    Thanks for replay ,,

    sorry i am not getting appropriate forum link to post this problem....
     
    I want to create Rad Grid as user control , so I can easy update my lots of grid's on  my application . I have create one user control for rad grid as per my business functionality and various properties ….

    Now I stuck on one point how can I pass the different  columns to my user control grid. I have tried creating GridColumnCollection as one type of property but it not working … how can I pass my column list to user control, to generate rad grid according column and columns type.

    Thank you
  31. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 06 Nov 2012 Link to this post

    Hi Rohan,

    It will be best to open a new forum thread or a support ticket and post your requirements there. Thus we will be able to easily track the different case you have and provide the most appropriate solution for each specific case.

    Greetings,
    Maria Ilieva
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017