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

Loading a UserControl Dynamically within NestedViewTemplate

4 Answers 192 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 09 Jan 2014, 05:17 PM
Hello There,

Let me start by saying I have done extensive searching regarding this issue and the items that I found weren't relevant to me or didn't seem to work.  My issue is that I have a <UserControl>  that I would like to dynamically add to the <NestedViewTemplate> of a RadGrid. The problem is that if I include the UserControl markup inside the NestedViewTemplate, it fires the UserControl events for each row within the RadGrid.  I would like to "Lazy" Load the UserControl upon the User Expanding a row within the RadGrid.  I have read examples of wrapping the UserControl inside an <asp:Panel> and toggling the Panels visibility property, but that doesn't seem to work.  

Could you please give an example of how to do this or a link to an article where this has been accomplished?

I've tried loading the UserControl dynamically, but it then loses the RadGrid's DataBinding Container and the controls inside the UserControl are no longer bound.

Thanks for you help in advance and I look forward to your response.

Chris   

4 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 09 Jan 2014, 08:27 PM
I am still looking for a solution to dynamically loading a user control inside the NestedViewTemplate of a RadGrid control.  DataBinding inside the UserControl is needed from the DataItem of the RadGrid.

Please help.
0
Pavlina
Telerik team
answered on 14 Jan 2014, 05:39 PM
Hello Chris,

To achieve the desired functionality you can handle the ItemCreated event, and if an item is expanded, load the user controls in the nested item. Then inside ItemDataBound you can populate the controls inside the User Control with data.

Additionally, I recommend you check out the Traversing detail tables/items in Telerik RadGrid help topic to learn how to access the nested table views.

Regards,
Pavlina
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Joel
Top achievements
Rank 1
answered on 01 Aug 2014, 06:55 PM
Hello Pavlina:

I tried to do as you wrote "and if an item is expanded, load the user controls in the nested item. ", but if i check the property "Expanded" of the item, this is always false.

So how can I, from  inside the ItemCreated event handler, validate if an item is expanded?.

Best Regards!!
0
Princy
Top achievements
Rank 2
answered on 04 Aug 2014, 06:16 AM
Hi Joel,

Please try the code in the PreRender event of the Grid.

C#:
void rgrdSample_PreRender(object sender, EventArgs e)
{
    foreach (GridDataItem item in rgrdSample.MasterTableView.Items)
    {
        if (item.Expanded)
        {
          //your code
        }
       else
        {
          //your code
        }
    }
}

Thanks,
Princy
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Pavlina
Telerik team
Joel
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or