Changing the paging text of a Telerik RadGrid

I was delving into the mysteries of the Telerik RadGrid. I needed to change the paging label in the bottom right corner of the grid because of, what else, users. In our application, we have parent and child records that are bound to the grid, and by default, the child records are hidden. The users only wanted the parent records to be shown in the paging label. So if I have a total of 20 records, with 15 parents and 5 children, the count should only say 15, the full text of the pager bar being: 15 items in 1 page.

I asked for the wisdom of the Telerik forums, which were very helpful. I was given the code and told to put it into the RadGrid PreRender event. And that seemed to work, but there was a problem in that we have other code that binds to LinkButtons, and one of the buttons was being rendered improperly by the call to rebind the RadGrid.

Luckily, it wasn’t difficult to fix: I just moved the code to change the paging label to the page PreRender event instead of the RadGrid PreRender event, and that worked:

        protected void Page_PreRender(object sender, EventArgs e)
        {
            string pageLabel = pagerRowCount > PageSize ? "pages" : "page";

            GridPagerItem pagerItem = (GridPagerItem)gridOrders.MasterTableView.GetItems(GridItemType.Pager)[0];
            gridOrders.PagerStyle.PagerTextFormat = "{4} " + pagerRowCount + " items in " + " {1} " + pageLabel;
            gridOrders.Rebind();
        }

 

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: