Archive for December, 2011

Double binding in a RadGrid in a RadWindow. Not rad, dude.

I ran across a problem when dealing with a Telerik RadWindow. On my page, I had this definition:

<telerik:RadWindow ID=”MyWindow” runat=”server” Title=”Scott’s Window” VisibleOnPageLoad=”false” Behavior=”Close” EnableShadow=”true” Modal=”true”>
</telerik:RadWindow>

The problem is that when I opened the window, then closed it by using the “X” in the top right corner, and then opened the window again, the control would be bound twice. And not just the RadGrid I had in the control, the entire page would be duplicated.

I tried everything I could think of. I tried removing the extra control (there was one being loaded when opening the window again) in the RadWindow’s ContentContainer.Controls collection. I tried stopping the processing of the second page binding.  I tried using the DestoryOnClose property. I tried going to lunch. Nothing worked.

So I cheated.

Instead of dealing with the mysterious double binding, I just removed the “X” from the menu bar by changing the Behavior property of the RadWindow:

Behavior=”None”

This hid the close button, as well as the minimize and maximize buttons. I didn’t need them, and the users didn’t need them, and if you can’t perform the action that causes the error, you can’t cause the error.

Advertisements

Leave a comment

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();
        }

 

Leave a comment