Hi,
I am trying to dynamically load some user controls into the nested view template when the row is expanded but nothing seems to work. I read all posts regarding nestedViewTemplate and couldn't find an answer.
Does anybody know how this can be done (if it can)?
Mario
I am trying to dynamically load some user controls into the nested view template when the row is expanded but nothing seems to work. I read all posts regarding nestedViewTemplate and couldn't find an answer.
Does anybody know how this can be done (if it can)?
Mario
3 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 04 May 2009, 04:48 AM
Hi Mro,
Try out the following code snippet to dynamically load the usercontrol to a nestedViewTemplate.
CS:
Thanks
Shinu
Try out the following code snippet to dynamically load the usercontrol to a nestedViewTemplate.
CS:
| protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridNestedViewItem) |
| { |
| //to access the nested item |
| GridNestedViewItem nestedItem = (GridNestedViewItem)e.Item; |
| PlaceHolder NestedViewTemplatePlaceHolder = (PlaceHolder)nestedItem.FindControl("NestedViewTemplatePlaceHolder"); |
| UserControl uctl = new UserControl(); |
| uctl.ID = "uctl1"; |
| Label lbl = new Label(); |
| lbl.ID = "lbl1"; |
| lbl.BackColor = System.Drawing.Color.Pink; |
| lbl.Text = "Hello"; |
| uctl.Controls.Add(lbl); |
| //to add the uctl to the NestedViewTemplatePlaceHolder |
| NestedViewTemplatePlaceHolder.Controls.Add(uctl); |
| } |
| } |
Thanks
Shinu
0
mro
Top achievements
Rank 1
answered on 04 May 2009, 04:59 PM
Thank you Shinu but that is not really what I am trying to do. I would like to load controls only into the expanded row.
So it should be like this:
Main Grid (Chemical Brothers, Massive Attack, Prodigy).
Nested View (empty - no control).
User Controls container (not loaded) which has 4 controls ( 2 grids, 1 repeater, 1 details view).
When the grid loads if no rows expanded then no controls should be loaded.
The user clicks on view details (expand row) for Prodigy.
Grid loads the container with 4 controls, gives to container Prodigy ID and container loads Prodigy info, all albums, all concerts, 5 most listened songs, user votes, but only for Prodigy.
What I did is I load user control in item created event and then in the item command I setup the Musician Id and call DataBind on the control from nested view. Not sure if that is the best way.
Mario
So it should be like this:
Main Grid (Chemical Brothers, Massive Attack, Prodigy).
Nested View (empty - no control).
User Controls container (not loaded) which has 4 controls ( 2 grids, 1 repeater, 1 details view).
When the grid loads if no rows expanded then no controls should be loaded.
The user clicks on view details (expand row) for Prodigy.
Grid loads the container with 4 controls, gives to container Prodigy ID and container loads Prodigy info, all albums, all concerts, 5 most listened songs, user votes, but only for Prodigy.
What I did is I load user control in item created event and then in the item command I setup the Musician Id and call DataBind on the control from nested view. Not sure if that is the best way.
Mario
0
Hello mro,
You may consider wrapping the content of the nestedview template in a panel and changing the visibility of that panel programmatically as demonstrated on this online demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx
Review the implementation in the code-behind file for more details. Thus merely the nested view for the expanded items in the grid will be rendered and bound to data.
Best regards,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.