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

RadGrid does not display on first page load but does on postback

4 Answers 589 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark Bourland
Top achievements
Rank 1
Mark Bourland asked on 17 Mar 2010, 04:58 PM
Hello,

I have a page with a drop-down. Based on the selection in the drop-down, data gets loaded and populates a RadGrid. I am using a custom user control for the EditTemplate, so I can't use radGrid.DataBind(). Instead, I have to use radGrid.MasterTableView.Rebind() in association with a NeedDataSource event handler.

My problem is that when I load the page initially, I populate the drop-down and automatically select a value (first item in the list) which triggers the databinding on the RadGrid. I can step through the code in debug mode and see that the grid is being populated with data (both when the DataSource is being set and when a derived property is visited when it's displayed as a column in the grid), but when the page displays, the grid doesn't get rendered. I can then manually choose an item from the drop-down, which triggers the same grid databinding code, it displays properly the second time.

How do I get it to display the grid the first time the page loads?

4 Answers, 1 is accepted

Sort by
0
Mark Bourland
Top achievements
Rank 1
answered on 17 Mar 2010, 08:42 PM
Additional info:

When debugging, I have noticed that the grid does get bound to the data correctly.  However, it is acting like the HTML output for the grid is not rendered until AFTER the page HTML has been sent to the browser.  Here is a simplified page lifecycle that I'm seeing:

Page_Load()
LoadData()
GridNeedDataSource()
<page is rendered to the browser without the grid>

<cause any kind of postback>
GridNeedDataSource()
<page is renderd to the browser WITH the grid>

I changed EnableViewState to false and the grid displays all the time, however I've lost almost all functionality within my edit template's custom user control, which is not acceptable.
0
Mark Bourland
Top achievements
Rank 1
answered on 17 Mar 2010, 09:15 PM
Yet more info:

From what I can tell, the view state is being modified after the page HTML is rendered and therefore, the grid is not being displayed until the first post back happens.

Why would disabling the viewstate on the grid (but not the page) cause the grid to properly display the first time the page is loaded?
Why would enabling the viewstate on the grid cause the grid to NOT properly display the first time the page is loaded?
How can I keep the benefits of having the viewstate enabled, but also display the grid on the first page load?
0
Mark Bourland
Top achievements
Rank 1
answered on 17 Mar 2010, 10:30 PM

I can't answer WHY it was happening, but the solution that works for me is to bind the grid to an ObjectDataSource.

<asp:ObjectDataSource ID="gridData" runat="server"/> 

I was already binding the grid to a property on the page which was a collection of type List:


protected
List<EquipmentGridItem> GridItems { get; set; } 

In order to use the ObjectDataSource, I created a wrapper method to return the list.


public
object GetGridData()  {      return GridItems;  } 

Then I bound the grid to the object data source.


protected
override void OnInit(EventArgs e)  {      base.OnInit(e);        grdUnits.DataSourceID = "gridData";      gridData.TypeName = typeof (ReservationEdit).ToString();      gridData.SelectMethod = "GetGridData";  } 

Kind of a convoluted solution, but it works.

0
Erik
Top achievements
Rank 2
answered on 18 Apr 2012, 12:49 PM
Think I got a similar problem. Mine was solved using the 
RadGrid1_NeedDataSource

Setting RadGrid1.DataSource to an array of object gave grid problems. A collapse/expand column was showed on the first page. navigating to 2nd page worked fine, back to the first gave drawing errors and the prev page + first page where highlighted below...  weird.

Erik
Tags
Grid
Asked by
Mark Bourland
Top achievements
Rank 1
Answers by
Mark Bourland
Top achievements
Rank 1
Erik
Top achievements
Rank 2
Share this question
or