LayoutTemplate AND Page.LoadTemplate

5 posts, 1 answers
  1. temperory temperory
    temperory temperory avatar
    6 posts
    Member since:
    Apr 2010

    Posted 02 Jan 2011 Link to this post

    Hi Dear

    When I use LayoutTemplate  in design time it`s work correctly but in runtime when i use "Page.LoadTemplate" method for loading template when DataBind() fired it thrown exception :

    "

    The RadListView control does not have an item placeholder specified.

    "

    RadListView1.PageSize = (int)contentList.PageSize;
    RadListView1.DataSource = contents;
    RadListView1.LayoutTemplate = Page.LoadTemplate(contentList.LayoutTemplate);
    RadListView1.ItemTemplate = Page.LoadTemplate(contentList.ItemTemplate);
    RadListView1.VirtualItemCount = totlaCount;
    RadListView1.DataBind();

    Best Regards.
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 03 Jan 2011 Link to this post

    Hello,

    Bellow links demonstrates how to create RadListView programmatically:
    http://demos.telerik.com/aspnet-ajax/listview/examples/definingstructure/programmaticdefinition/defaultcs.aspx

    http://www.telerik.com/help/aspnet-ajax/listview-programmatic-definition.html

    All the best,
    Nikolay
    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
  4. temperory temperory
    temperory temperory avatar
    6 posts
    Member since:
    Apr 2010

    Posted 04 Jan 2011 Link to this post

    Hi

    Tanks for your answer.I see all examples and help but there is no sample that use Page.LoadTemplae method.
    Below you can see my sample that thrown exception :

    Server Error in '/' Application.
    --------------------------------------------------------------------------------
     
    The RadListView control does not have an item placeholder specified.
    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.InvalidOperationException: The RadListView control does not have an item placeholder specified.
     
    Source Error:
     
     
    Line 20:             RadListView1.LayoutTemplate = Page.LoadTemplate("LayoutTemplate.ascx");
    Line 21:             RadListView1.ItemTemplate = Page.LoadTemplate("ItemTemplate.ascx");
    Line 22:             RadListView1.DataBind();
    Line 23:         }
    Line 24:


    Default.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="RadListView.Default" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            </telerik:RadScriptManager>
            <telerik:RadListView ID="RadListView1" runat="server">
            </telerik:RadListView>
        </div>
        </form>
    </body>
    </html>


    Default.aspx.cs

    public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                 
            }
     
            protected void Page_PreInit(object sender, EventArgs e)
            {
                RadListView1.DataSource = GetStudent();
                RadListView1.LayoutTemplate = Page.LoadTemplate("LayoutTemplate.ascx");
                RadListView1.ItemTemplate = Page.LoadTemplate("ItemTemplate.ascx");
                RadListView1.DataBind();
            }
     
            private List<Student> GetStudent()
            {
                List<Student> students = new List<Student>();
                Student student = new Student();
                student.Name = "Jim";
                student.LastName = "McDonald";
                students.Add(student);
     
                Student student2 = new Student();
                student2.Name = "Roza";
                student2.LastName = "McDonald";
                students.Add(student2);
     
                return students;
            }
        }
     
        public class Student
        {
            public string Name { get; set; }
            public string LastName { get; set; }
     
        }

    ItemTemplate.ascx

    Name : <%# Eval("Name") %><br />
    LastName : <%# Eval("LastName") %><br />

    LayoutTemplate.ascx

    <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>


    Best Regards.
  5. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 07 Jan 2011 Link to this post

    Hello,

    The error is cause because RadListView could not find the place holder control in the layout template.
    This is due to the fact that the UserControl that is used as layout template is INamingContainer and FindControl does not resolve correctly.

    However this is expected behavior you can even replicate it by using ListView instead of RadListView control.

    To have this working you can inherit RadListView and override RetrivePlaceHolderControl method and provide custom implementation for finding control in container.

    Greetings,
    Nikolay
    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.
  6. temperory temperory
    temperory temperory avatar
    6 posts
    Member since:
    Apr 2010

    Posted 07 Jan 2011 Link to this post

    Tanks.

    [ToolboxData("<{0}:myRadListView runat=server></{0}:myRadListView>")]
    public class myRadListView : Telerik.Web.UI.RadListView
    {
        protected override Control RetrivePlaceHolderControl(Control container, string placeholderId)
        {
            return container.Controls[0].FindControl(placeholderId);
        }
    }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017