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

Setting SelfHierarchySettings from code behind

2 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 08 Oct 2010, 01:20 PM
Hi guys!
I have a master page which holds RadGrid and a few columns (ClientSelect, Edit, Delete). The rest of the columns are added during Page_Init inside content page during runtime. It all worked fine, untill I needed to create a self-hierarchy structure. When I set SelfHierarchySettings on master page, it works, but other pages that don't need it become unusable. If I set those settings in code-behind, there are no child rows rendered.
We had an idea to use <%= %> on Master page to set KeyName and ParentKeyName but it results in a compilation error (like this

<

 

SelfHierarchySettings KeyName="<%=KeyName%>" ParentKeyName="<%=ParentKeyName%>" />

So far I found only samples when grid is either defined on aspx, or completely created programmatically. If you could provide a sample similar to my case, I'd be very thankful.

 

2 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 13 Oct 2010, 08:08 AM
Hi Andy,

RadGrid does not support mixing declarative grid columns with grid columns added dynamically at runtime. You should either create all the columns in the grid programmatically, or else define them all in the ASPX file. Review the help article below for more information:
Programmatic creation

All the best,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Andy
Top achievements
Rank 1
answered on 13 Oct 2010, 08:16 AM
Thanx for reply! Just posted this in another thread :)

In fact it does support mixed mode. I have a grid defined in aspx on Master page, with a few common columns (edit and delete). And on content pages I add the rest of the columns from code-behind. It works fine as long as I add columns to the collection before setting their properties.
As for detail table - I create them completely programmatically, so there're no issues too. I ran into problem when I needed to use "self-refferencing hierarchy" - the detail tables, which are created automatically, copy the structure of MasterTableView, but it seems to happen quite early in the life-cycle, thus, my custom columns (which I add from code-behind) are present in detail table only untill the first call-back occures.
We've found a solution though - I created a class which inherits RadGrid, and override OnInit,where I add custom columns to MasterTableView and set SelfHierarchySettings (KeyName and ParentKeyName). This allows custom columns and selfHierarchySettings to be added to the viewstate and they persist thru all call-backs. Let me know if you need more details on the solution.

But in fact, it would be nice if there was a way to define grid on Master Page and it's structure on content page.. like you can do with ListView, where you can define ItemTemplate etc...

And btw, the original question was about SelfHierarchySettings.
Tags
Grid
Asked by
Andy
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Andy
Top achievements
Rank 1
Share this question
or