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

[Solved] RAD Grid Customized Pager

4 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Das
Top achievements
Rank 1
Das asked on 01 Jan 2009, 09:26 AM
Hi,
I have customized the RADGrid Pager in such a way that it uses NexPrevandNumeric Pager Style and has a dropdown to change the pagesize. The issue I face is mentioned below:

1. Consider a grid with total records of 21
2. If I select 10 records as page size the paging works.
3. If I select 25 from the dropdown for setting the page size the entire pager disappears.

PFB the code used for adding the controls and the code to add the controls.

public class RADGridPager:Control
    {
        private GridTableView tableView;
        DropDownList ddlPageSize;
        public RADGridPager(GridTableView tableView)
        {
            this.tableView = tableView;
            this.EnsureChildControls();
        }
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            this.Controls.Add(new LiteralControl("Change Page Size: "));
            ddlPageSize = new DropDownList();
            ddlPageSize.ID = "ddlPager";
            ddlPageSize.Items.Add(new ListItem("10", "10"));
            ddlPageSize.Items.Add(new ListItem("15", "15"));
            ddlPageSize.Items.Add(new ListItem("20", "20"));
            ddlPageSize.Items.Add(new ListItem("25", "25"));
            ddlPageSize.AutoPostBack = true;
            ddlPageSize.Attributes.Add("style", "font-family: verdana; font-size: 10px;");
            ddlPageSize.SelectedIndexChanged += new EventHandler(ddlPageSize_SelectedIndexChanged);
            this.Controls.Add(ddlPageSize);
            this.Controls.Add(new LiteralControl("<br /><br />"));
        }

        protected override void OnPreRender(EventArgs e)
        {
            ddlPageSize.SelectedValue = tableView.PageSize.ToString();
            base.OnPreRender(e);
        }

        protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.tableView.PageSize = int.Parse(this.ddlPageSize.SelectedValue);
            this.tableView.CurrentPageIndex = 0;
            this.tableView.Rebind();
        }
    }

Code to consume the RADGrid Pager:

protected void rgUserList_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridPagerItem)
            {
                GridPagerItem pagerItem = (GridPagerItem)e.Item;
                pagerItem.PagerContentCell.Controls.Add(new LiteralControl("<br /><br />"));
                pagerItem.PagerContentCell.Controls.Add(new RADGridPager(e.Item.OwnerTableView));
            }
        }
Please let me know how to go about this. Thanks.




4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Jan 2009, 05:16 AM
Hi Das,

Try setting the AlwaysVisible property of the PagerStyle to true.

ASPX:
        <PagerStyle   AlwaysVisible="true" /> 


Thanks
Shinu
0
Shuchi Bhalla
Top achievements
Rank 1
answered on 09 Apr 2009, 02:20 AM
Hello Das/Shinu

I tried implementing the custom pager from the code snippet in this thread. I have also implemented custom pagine. My problem is that I am unable to retrieve the new page size value. Seems like before I can read the newly selected page size, the grid's ItemCreated event is fired and the custom pager values are reinitialized.

So the vaue passed to my pagin function is always the initial value.

Am I missing some connecting code here? 

~Shuchi
0
Sebastian
Telerik team
answered on 09 Apr 2009, 06:30 AM
Hello Shuchi,

Have you considered using the new default grid pager (NextPrevAndNumeric) introduced in the Q1 2009 release of RadControls for ASP.NET AJAX? Thus you will not need to design your own custom pager and handle paging manually with code. The new pager is demonstrated on this online demo:

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/paging/defaultcs.aspx (see the third grid on it)

Please have in mind, however, that the skins for the controls are not backwards compatible in the new release and you can use our skin converter tool if you intend to port old skins:

http://blogs.telerik.com/tervelpeykov/posts/09-03-20/using_pre-q1_2009_skins_with_q1_2009.aspx
http://www.telerik.com/community/forums/aspnet-ajax/general-discussions/all-radcontrols-q3-2008-skins-are-now-compatible-with-the-q1-2009-release.aspx

You may also review the general 'Changes and backwards compatibility' chapter from the online documentation:

http://www.telerik.com/help/aspnet-ajax/radcontrols-changes-backwards-compatibility.html

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Yavor
Telerik team
answered on 09 Apr 2009, 06:36 AM
Hi Shuchi,

The code supplied looks correct, and should handle the task at hand. If the issue persists at your end, you can open a formal support ticket, and send us the problematic code, in the form of a small working project, for additional testing.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Das
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Shuchi Bhalla
Top achievements
Rank 1
Sebastian
Telerik team
Yavor
Telerik team
Share this question
or