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

Forums / Developing with Sitefinity / Custom List/Details View

Custom List/Details View

7 posts, 0 answered
  1. Nadya
    Nadya avatar
    52 posts
    Registered:
    17 Dec 2008
    16 Feb 2010
    Link to this post
    Hello Telerik team,

    I am developing a web site using Sitefinity 3.7 SP2 and I have an Employee custom module.
    I need to create a EmployeeListDetails view for its items, but I cannot make it work.
    First I've tried inheriting from ContentView and then overriding CreateChildControls the following way :
    protected override void CreateChildControls()
            {
                base.ProviderName = "Employees";
     
                if (Page == null || !Page.IsPostBack)
                {
                    base.ItemListTemplatePath = "~/Templates/Controls/Sitefinity/EmployeeList.ascx";
                    base.SingleItemTemplatePath = "~/Templates/Controls/Sitefinity/EmployeeDetails.ascx";
                }
     
                base.CreateChildControls();
     
                if (Page == null || !Page.IsPostBack)
                {
                    if (this.SelectedItemId != Guid.Empty)
                    {
                        Literal ltrEmployeeDetailsPageTitle = (Literal)base.SingleContainer.Controls[0].FindControl("ltrEmployeeDetailsPageTitle");
                        ltrEmployeeDetailsPageTitle.Text = this.EmployeeDetailsPageTitle;
                    }
                    else
                    {
                        Literal ltrEmployeeListPageTitle = (Literal)base.ListContainer.Controls[0].FindControl("ltrEmployeeListPageTitle");
                        ltrEmployeeListPageTitle.Text = this.EmployeeListPageTitle;
                    }
                }
     
                if (this.SelectedItemId != Guid.Empty)
                {//some logic for details here}
    }
    But I keep having null reference exception on databinding the repeater from the list control - seems like it is not getting the items from the provider.

    I am doing it as NewsView and EventsView and I see there are two attributes I don't know how to set for my class. For EventsView these are:
    [ToolboxData("<{0}:EventsView runat=\"server\"></{0}:EventsView>")]
    [ControlDesigner("Telerik.Events.WebControls.Design.EventsViewDesigner, Telerik.Events")]

    So the issue is with this designer. There's a thread with similar topic: http://www.sitefinity.com/support/forums/sitefinity-3-x/developing-with-sitefinity/productspublicview.aspx

    From there I get my second option to create Frontend folder in my module and load my EmployeesListDetailsView from there. But I am again getting to the CustomDesigner class.
    I see the code file but how the template should look like. Because I will load the employee list view using 
    base.ItemListTemplatePath
    and details view using :
    base.SingleItemTemplatePath

    So what to do with this designer ? 
    If I am getting something wrong, please give me directions.

    I need it as soon as possible.

    Thank you very much!

    All best wishes Nadya
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    16 Feb 2010
    Link to this post
    Hello Nadya,

    1. Try overriding CreateDataSource to bind the ContentView control to your custom data. You do not have to populate the repeater manually.

    sample code

    protected override void CreateChildControls()
      {
          base.CreateChildControls();
         
      }
     
      protected override IList CreateDataSource()
      {
          contentManager = new ContentManager("News");
          IList contentList = contentManager.GetContent();
          return contentList;
      }


    2. ControlDesigner - it is used when you have a control that has a custom designer as events and news.

    sample code

    public class ControlDesignerCustom : Telerik.Framework.Web.Design.ControlDesigner

    [ControlDesignerAttribute("ControlDesignerCustom, App_Code")]
    public class ControlWithCustomDesigner : SimpleControl

    ToolboxData - specify the default tag generated for a custom control when it is dropped on a page.

    3. You can set the embedded templates for a custom control as shown below

    public override string ItemListTemplateName
       {
           get
           {
               return CustomContentViewControl.CustomItemListTemplateName;
           }
       }

       public override string SingleItemTemplateName
       {
           get
           {
               return CustomContentViewControl.CustomSingleItemTemplateName;
           }
       }
     
     
     
     
       #region Constants
     
       private const string CustomItemListTemplateName = "SampleModule.Resources.ListPageMaster.ascx";
     
       private const string CustomSingleItemTemplateName = "SampleModule.Resources.ListPageDetails.ascx";
     
       #endregion


    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.
  3. Nadya
    Nadya avatar
    52 posts
    Registered:
    17 Dec 2008
    17 Feb 2010
    Link to this post
    Hi Ivan!

    Thank you very much for the quick response, but unfortunately I still have some issues.
    Yes if I remove the databind event and override CreateDataSource() I manage to load my control. But I still don't get if I don't have the repeater event how can I populate my data. I have more complicated situation then just name some literals on the List control with my modules metafields. I have to do some formatting and stuff.
    Also in my variant of CreateChildControls() I am handling the single item case - if I do not overide it I can't see how I will navigate to it at first place and then how I will populate my details view.
    Please give me a little more help.

    Thank you again - I am looking forward to reading your answer!

    All best, Nadya
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 Feb 2010
    Link to this post
    Hello Nadya,

    You can access the content items from the repeater as shown below

    protected override void CreateChildControls()
     {
         base.CreateChildControls();
         ListContainer.RepeaterControl.DataSource = CreateDataSource();
         ListContainer.RepeaterControl.ItemDataBound += new RepeaterItemEventHandler(RepeaterControl_ItemDataBound);
         ListContainer.DataBind();
     
         
     }
     
     void RepeaterControl_ItemDataBound(object sender, RepeaterItemEventArgs e)
     {
         if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
         {
             IContent conten = e.Item.DataItem as IContent;
         }
     }

    You can also use SiteItemMetadata to access the content item or SetSingleItemContent

    Kind regards,
    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.
  5. Nadya
    Nadya avatar
    52 posts
    Registered:
    17 Dec 2008
    17 Feb 2010
    Link to this post
    Hi Ivan!

    Thank you for your help. I solve my issues - what I was missing is exactly overriding SiteItemMetadata method.
    I was not sure how exactly to do it, so I searched and it appears that BlogPosts control is similar to what I was doing, so I use reflector and I wrote my code.

    So thank you again I wish you fruitful day!

    All Best, Nadya
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 Feb 2010
    Link to this post
    Hi Nadya,

    Always glad to help. You can follow the same logic for all controls that inherits from ContentView class.

    Sincerely yours,
    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.
  7. Nadya
    Nadya avatar
    52 posts
    Registered:
    17 Dec 2008
    17 Feb 2010
    Link to this post
    Hi,
    I just want to add one more thing for everybody that will be stuck on issue like this :)

    overriding CreateDataSource() is ok but not if you want to put telerik's pager on the page. You should handle the paging by yourself if you keep the overriding. Otherwise the pager is paged correctly but you see all items because you are returning all of them.

    Actually it is enought to override the ProviderName Property :

    public override string ProviderName
           {
               get
               {
                   return "Employees";
               }
           }

    And it is all working.

    All best, Nadya
Register for webinar
7 posts, 0 answered