+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Problems with RadListView and templates (Unable to cast object...RootBuilder)

Problems with RadListView and templates (Unable to cast object...RootBuilder)

2 posts, 1 answered
  1. bemara57
    bemara57 avatar
    135 posts
    Registered:
    27 Mar 2008
    18 Aug 2010
    Link to this post
    I am having trouble using a RadListView in a template. I am inheriting a SimpleControl to point to a control template. In the control template I have:

    <%@ Control Language="C#" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <telerik:RadListView ID="lvLots" runat="server"
        AllowPaging="True"
        DataKeyNames="guid">
        <ItemTemplate>
            <div class="rlvI content">
                <div class="image">
                    <a href='<%# Eval("link")%>'><img src='<%# Eval("guid")%>' alt="<%# Eval("title")%>"></a>
                </div>
                <p>
                    <span class="title"><%# Eval("title")%></span>
                </p>
            </div>
        </ItemTemplate>
        <LayoutTemplate>
            <div class="RadListView RadListViewFloated RadListView_<%# Container.Skin %>">
                <div class="rlvFloated rlvAutoScroll">
                    <div id="itemPlaceholder" runat="server">
                    </div>
                </div>
                <br />
                <telerik:RadDataPager ID="RadDataPager1" runat="server">
                    <Fields>
                        <telerik:RadDataPagerButtonField />
                    </Fields>
                </telerik:RadDataPager>
            </div>
        </LayoutTemplate>
        <EmptyDataTemplate>
            <asp:Label ID="lblEmptyMessage" runat="server" CssClass="lots-empty" />
        </EmptyDataTemplate>
    </telerik:RadListView>

    I get the below error:

    Server Error in '/sitefinitystandard' Application.

    Unable to cast object of type 'Telerik.Cms.Web.UI.Templates.RootBuilder' to type 'Telerik.Cms.Web.UI.Templates.CollectionBuilder'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidCastException: Unable to cast object of type 'Telerik.Cms.Web.UI.Templates.RootBuilder' to type 'Telerik.Cms.Web.UI.Templates.CollectionBuilder'.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [InvalidCastException: Unable to cast object of type 'Telerik.Cms.Web.UI.Templates.RootBuilder' to type 'Telerik.Cms.Web.UI.Templates.CollectionBuilder'.]
       Telerik.Cms.Web.UI.Templates.PropertyBuilder.SetProperty(Object component, Control bindingContainer) +410
       Telerik.Cms.Web.UI.Templates.PropertiesBuilder.SetProperties(Object component, Control bindingContainer) +131
       Telerik.Cms.Web.UI.Templates.ObjectBuilder.CreateObject(Control bindingContainer) +500
       Telerik.Cms.Web.UI.Templates.ControlBuilder.CreateControl(Control bindingContainer) +15
       Telerik.Cms.Web.UI.Templates.SimpleTmplate.InstantiateIn(Control container) +214
       Telerik.Web.UI.RadListView.InitializeLayoutTemplate() +136
       Telerik.Web.UI.RadListView.EnsureLayoutTemplate() +62
       Telerik.Web.UI.RadListView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +25
       Telerik.Web.UI.RadListView.PerformDataBinding(IEnumerable data) +49
       System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
       Telerik.Web.UI.RadListView.PerformSelect() +24
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
       Telerik.Web.UI.RadListView.DataBind() +17
       Telerik.Web.UI.RadListView.AutoDataBind(RadListViewRebindReason rebindReason) +122
       Telerik.Web.UI.RadListView.OnLoad(EventArgs e) +168
       System.Web.UI.Control.LoadRecursive() +50
       System.Web.UI.Control.LoadRecursive() +141
       System.Web.UI.Control.LoadRecursive() +141
       System.Web.UI.Control.AddedControl(Control control, Int32 index) +265
       System.Web.UI.ControlCollection.Add(Control child) +80
       Telerik.Cms.Web.UI.SimpleControl.CreateChildControls() +90
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +44
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
    

    Is it not allowed to add a complex control in the template?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    20 Aug 2010
    Link to this post
    Hi bemara57,

    Most probably you have an  empty collection. I created a sample example and there is no problem with SimpleControl and RadListView

    template

    <telerik:RadListView ID="lvLots" runat="server"
        AllowPaging="True"
        DataKeyNames="ID">
        <ItemTemplate>
            <div class="rlvI content">
                <div class="image">
                      <asp:HyperLink  runat="server" ID="link1" Text='<%# DataBinder.Eval(Container.DataItem, "Name")%>'  NavigateUrl="#"></asp:HyperLink>
                </div>
                <p>
              
                </p>
            </div>
        </ItemTemplate>
        <LayoutTemplate>
            <div class="RadListView RadListViewFloated >
                <div class="rlvFloated rlvAutoScroll">
                    <div id="itemPlaceholder" runat="server">
                    </div>
                </div>
                <br />
                <telerik:RadDataPager ID="RadDataPager1" runat="server">
                    <Fields>
                        <telerik:RadDataPagerButtonField />
                    </Fields>
                </telerik:RadDataPager>
            </div>
        </LayoutTemplate>
        <EmptyDataTemplate>
            <asp:Label ID="lblEmptyMessage" runat="server" CssClass="lots-empty" />
        </EmptyDataTemplate>


    custom control

    public class SimpleControlTest : SimpleControl
    {
        public SimpleControlTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }
     
     
        public override string LayoutTemplatePath
        {
            get
            {
                return "~/CustomControls/SimpleControlTest.ascx";
            }
           
        }
     
        protected override void InitializeControls(System.Web.UI.Control controlContainer)
        {
            base.InitializeControls(controlContainer);
            if (RadListViewControl != null)
            {
                var manager = new CmsManager();
                RadListViewControl.DataSource = manager.GetPages();
                RadListViewControl.DataBind();
            }
        }
     
     
        protected virtual RadListView RadListViewControl
        {
     
            get
            {
                return this.Container.GetControl<RadListView>("lvLots", false, Telerik.Framework.Web.TraverseMethod.DepthFirst);
            }
        }
    }


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
2 posts, 1 answered