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

[Solved] Nested View Tamplate and user controls

3 Answers 257 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mro
Top achievements
Rank 1
mro asked on 30 Apr 2009, 11:35 AM
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

3 Answers, 1 is accepted

Sort by
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:
 
 
  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



0
Sebastian
Telerik team
answered on 07 May 2009, 12:53 PM

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,

Sebastian
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.
Tags
Grid
Asked by
mro
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
mro
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or