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

[Solved] Column metadata lost on Postback

1 Answer 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dewang Shah
Top achievements
Rank 1
Dewang Shah asked on 25 Jan 2010, 12:44 PM
Hi,

I am building my Grid structure in the code-behind (Page_Load when !Page.IsPostBack). I am using advanced data binding via the OnNeedDataSource event.

When I first load my page, the structure and data are fine. However, on a post-back the meta data of the columns is lost so I am left with no headers, and no data types on my columns. So all the rows just show "System.Data.DataRowView" as the value for each column
ViewState is enabled.

Any ideas? Am I missing an event handler to rebind the column data?

Thanks,
Dewang

1 Answer, 1 is accepted

Sort by
0
Dewang Shah
Top achievements
Rank 1
answered on 25 Jan 2010, 04:13 PM
I managed to find what was wrong!

I had a template column in my grid and was creating the structure in Page_Load. But then I saw this line that I had missed earlier on this page - http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html

"Creating columns in the Page_Load event handler does not work for template columns. For the controls inside a template to persist their ViewState, the grid must be generated completely in the code-behind using the Page_Init event (see below). That way, template controls are instantiated before the LoadViewState event of the page."

Moved the code to Page_Init and it works!
Tags
Grid
Asked by
Dewang Shah
Top achievements
Rank 1
Answers by
Dewang Shah
Top achievements
Rank 1
Share this question
or