More in this section

Forums / Developing with Sitefinity / ViewModeControl - data binding

ViewModeControl - data binding

5 posts, 2 answered
  1. Andree
    Andree avatar
    44 posts
    Registered:
    11 Jan 2010
    05 Feb 2010
    Link to this post

    Hi Ivan,

    I'm currently writing a frontend control within a pluggable module, and the source code of it looks as follows:

    public class ArticlesListing<THost> : ViewModeControl<THost> where THost : Control
        {
            /// <summary>
            /// Template resource name
            /// </summary>
            private const string layoutTemplateName = "Eularis.Sitefinity.Articles.Resources.ControlTemplates.Frontend.ArticlesListing.ascx";
      
            /// <summary>
            /// Custom layout template for the control
            /// </summary>
            [WebSysTemplate(layoutTemplateName, "ArticlesListing_Template_Desc", "/Articles", false, "2010-02-05")]
            public override string LayoutTemplatePath
            {
                get
                {
                    return base.LayoutTemplatePath;
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }
      
            /// <summary>
            /// Template name
            /// </summary>
            protected override string LayoutTemplateName
            {
                get
                {
                    return layoutTemplateName;
                }
            }
      
            /// <summary>
            /// Category drop down
            /// </summary>
            protected virtual ListControl Category
            {
                get
                {
                    return base.Container.GetControl<ListControl>("Category", true);
                }
            }
      
            /// <summary>
            /// Keywords filtering
            /// </summary>
            protected virtual ITextControl Keywords
            {
                get
                {
                    return base.Container.GetControl<ITextControl>("Keywords", true);
                }
            }
      
            /// <summary>
            /// Search button
            /// </summary>
            protected virtual IButtonControl Search
            {
                get
                {
                    return base.Container.GetControl<IButtonControl>("Search", true);
                }
            }
      
            protected virtual Repeater Listing
            {
                get
                {
                    return base.Container.GetControl<Repeater>("Listing", true);
                }
            }
      
            /// <summary>
            /// Initialise child controls
            /// </summary>
            protected override void InitializeControls(Control viewContainer)
            {
                BindGrid();
            }
      
            private void BindGrid()
            {          
                ContentManager manager = new ContentManager("Articles");
      
                Listing.DataSource = manager.GetContent();
                Listing.DataBind();
            }
        }

    It's a simple example of retrieving content from my custom provider (Articles), and displaying them onto a standard asp:Repeater control.

    However, when debugging, the GetContent() method returns 3 CmsContentBase items, and once DataBound, the Repeater shows 3 entries within its Items collection.

    When the page finally loads, there are no repeater items in view. I have tried changing the Repeater code to simplify it as much as possible so it looks like this:

    <asp:Repeater runat="server" ID="Listing">
        <ItemTemplate>
            Hello is this working.
        </ItemTemplate>
    </asp:Repeater>

    But the page still shows blank output.

    Any ideas what I'm doing wrong with data binding and the ViewModeControl?


    Regards,
    Alvaro
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    05 Feb 2010
    Link to this post
    Hi Alvaro,

    The code I see does not represent the public control. It is a backend view. Generally you do not bind the repeater correctly. Below is sample code that you can use



    RadRotator1.DataSource = list;
          RadRotator1.ItemDataBound += new RadRotatorEventHandler(RadRotator1_ItemDataBound);
          RadRotator1.DataBind();
     
     
     void RadRotator1_ItemDataBound(object sender, RadRotatorEventArgs e)
      {
          
         Label lbl =  e.Item.FindControl("rotatorLabel") as Label;
         IContent cnt = e.Item.DataItem as IContent;
         lbl.Text = (string)cnt.GetMetaData("Title");
      }

    <telerik:RadRotator ID="RadRotator1" runat="server"
    RotatorType="AutomaticAdvance"  BorderWidth="4px"
    Width="100px"
    Height="100px"
    ScrollDirection="Down" >
       <ItemTemplate>
     <asp:Label runat="server" ID="rotatorLabel"/>
       </ItemTemplate>
    </telerik:RadRotator>


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
    Answered
  3. Andree
    Andree avatar
    44 posts
    Registered:
    11 Jan 2010
    05 Feb 2010
    Link to this post
    Hi Ivan,

    If VieModeControl is a backend view, what class should I be inheriting from to make it a frontend view/control?


    Regards,
    Alvaro
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    05 Feb 2010
    Link to this post
    Hi Alvaro,

    You can inherit from ContentView, SimpleControl or CompositeControl classes.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
    Answered
  5. Andree
    Andree avatar
    44 posts
    Registered:
    11 Jan 2010
    05 Feb 2010
    Link to this post
    Aha perfect, I have it all up and running now.

    Many thanks Ivan.


    Alvaro
Register for webinar
5 posts, 2 answered