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

Problem: Cell styles are not applied to new rows when changing the RadGrid page size

5 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike Chabot
Top achievements
Rank 1
Mike Chabot asked on 25 May 2012, 05:49 AM

Scenario: A RadGrid is populated on the client side using JavaScript calls to Web services after the page finishes loading. The grid starts out empty on the server side. The only notable problem I see is that table cell styles are not applied to new rows after increasing the page size in the NextPrevNumericAndAdvanced pager. An example table cell style is cell alignment. The original rows might have cells with align="right" attributes, but all the new rows that get added after increasing the page size have plain td tags with no attributes, making the grid look unusual. My current fix is to hide that page size control, but I would like to get this working.

 

What seems to happen is that an empty grid is created with the proper td attributes, but the empty grid does have enough blank rows to match the new larger page size.

 

For example, start with a page size of 3, a blank 4 row grid is created then populated with data, with the last row being removed. I think the extra row is for the optional footer, which the grid does not have. Change the page size to 10. After the postback, a blank 4 row grid is created, then populated with 10 rows, which properly expands the visible rows to 10, but the last six rows lack formatting attributes.

 

I’m not sure the best way to handle this issue.

5 Answers, 1 is accepted

Sort by
0
Mike Chabot
Top achievements
Rank 1
answered on 25 May 2012, 05:52 AM
I should mention I am using the 2012 Q1 SP1 controls, VB.NET, ASP.NET 4.0. I've seen this problem since back in 2010, so it isn't a new issue.
0
Tsvetina
Telerik team
answered on 29 May 2012, 06:45 AM
Hi Mike,

This is expected as when increasing the page size the last two rows elements are copied to create the new ones but any custom styling applied to them is not copied. I would advise you to handle the client-side OnRowCreated or OnRowDataBound event and assign a className to the tr elements that you can use to apply your styles.

All the best,
Tsvetina
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.
0
Mike Chabot
Top achievements
Rank 1
answered on 31 May 2012, 07:26 PM
Thank you. Is this page size change behavior documented anywhere? It is unexpected that the column styles defined on the server are only used for the first four rows of a grid that is populated on the client.
0
Mike Chabot
Top achievements
Rank 1
answered on 31 May 2012, 10:02 PM
I have done more testing and I think the issue might be something different. I should mention that the page size change is handled on the server-side after a postback, not in the browser. The RadGrid is created on Page_Init with the default page size, then the RadGrid1_PageSizeChanged handler is called where I do this:
pageSize = e.NewPageSize
RadGrid1.PageSize = pageSize
RadGrid1.VirtualItemCount = pageSize
RadGrid1.Rebind()

However, the Rebind() call here does not trigger a call to the NeedDataSource handler, so the RadGrid1.Items.Count retains the old value, not the new pageSize value, and not enough rows are created in the blank grid template.

In the PageSizeChanged handler, if I delete the grid entirely and add it back with the new page size, the grid template sent to the browser contains the correct number of rows and the formatting problem goes away, although I’m sure there is a better solution. The solution probably involves getting the NeedDataSource event to fire after the PageSizeChange handler finishes, unless it is recommended to send an empty table to the browser and do all the formatting using the client-side event handlers.

0
Mike Chabot
Top achievements
Rank 1
answered on 31 May 2012, 11:26 PM

I found the fix for my problem, which was to turn ViewState on at the page level and for the RadGrid control. The "Optimizing ViewState usage" part of the manual suggests that disabling ViewState can cause a lot of problems with RadGrid and is not recommended.

Tags
Grid
Asked by
Mike Chabot
Top achievements
Rank 1
Answers by
Mike Chabot
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or