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

Pass ItemTemplate From User Control Instance to ListView ItemTemplate in User Control

1 Answer 114 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Jeremy Zoerman
Top achievements
Rank 1
Jeremy Zoerman asked on 03 Feb 2011, 06:03 AM

I am trying to pass an ItemTemplate from an instance of a user control to a ListView ItemTemplate in a user control.

------------------- USER CONTROL .ASCX.CS -------------------
    [TemplateContainer(typeof(ItemTemplateContainer))]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    [TemplateInstance(TemplateInstance.Single)]
    public ITemplate ItemTemplate { get; set; }
    public class ItemTemplateContainer : Control, INamingContainer { }

    protected void Page_Init()
    {
        if (ItemTemplate != null)
        {
            ItemTemplateContainer container = new ItemTemplateContainer();
            ItemTemplate.InstantiateIn(container);
            //THIS IS WHERE I AM STUCK - HOW DO I ASSIGN THE TEMPLATE FROM .ASPX TO THE RADLISTVIEW HERE?
        }
        else
            //If no custom template specified load default
            RadListView1.ItemTemplate = Page.LoadTemplate("/someDefault/Standard.ascx");
    }

------------------- USER CONTROL INSTANCE .ASPX -------------------
<uc:MyControl ID="MyControl1" runat="server" >
    <ItemTemplate>
            ...unique template...
    </ItemTemplate>
</uc:MyControl>

Thanks,
Jeremy

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 08 Feb 2011, 03:21 PM
Hi Jeremy,

Can you specify if the LoadTemplate() method works? You can try using the Page.LoadControl() method instead.
However I would suggest that you add the desired user control declaratively in the RadListView ItemTemplate.

Kind regards,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
ListView
Asked by
Jeremy Zoerman
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or