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

2 posts, 0 answers
  1. Jeremy Zoerman
    Jeremy Zoerman avatar
    3 posts
    Member since:
    Apr 2010

    Posted 03 Feb 2011 Link to this post

    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

  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 08 Feb 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top