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

Forums / Developing with Sitefinity / CustomDataSource for List

CustomDataSource for List

6 posts, 0 answered
  1. Ben
    Ben avatar
    18 posts
    Registered:
    12 May 2008
    15 Jul 2009
    Link to this post

    This may be easy and obvious to others, but it’s taking me for a ride.  Can anyone help?

    Goal

    The immediate goal is to display an expandable list sorted by headline.  The larger goal is to learn, by implementing this list, how to extend and customize controls.  But let’s get the basic job done first.

    Attempts

    ·         I’ve created a DLL that has a static class, containing a static method, that returns a DotNet List<custom type> (the custom type contains Headline and Content properties).  I’ve attempted to point to this data source in the expandable list’s CustomDatasource property, but it won’t accept it.  I’ve tried <namespace>.<classname>.<methodname>, and as many varieties as I could think of, but no luck.  How exactly is CustomDataSource used?  How do I define the datasource, where do I put it, and what’s the correct syntax for referencing it and using it declaratively?  This would seem the best option, but if this isn’t possible, maybe another approach would work.

    ·         I’ve started trying to wrap a list in a custom user control, and access my datasource directly.  What class, in what assembly would need to be overridden to do this for an expandable list?

     

    If all of this is documented somewhere and I’ve missed it (I admit this is possible), please let me know where to look.  Everything I’ve read has done little to get me to my goal.

     

    Thanks,

                Ben

  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    21 Jul 2009
    Link to this post
    Hello Ben,

    Thank you for your question.

    The CustomDataSource property is used for specifying a custom IList of Lists module items. Here is how we use it in the control:

     IList dataSource = null
     
      if(this.listsIds != null
         dataSource = this.Manager.GetListsByIds(this.listsIds); 
             
      if (customDataSource != null
         dataSource = customDataSource; 

    The Manager class is defined by ListManager Manager.

    The extended control could look like the following:
    App_Code\ListsDisplayEx.cs
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using Telerik.Lists.WebControls; 
    using System.Collections; 
    using Telerik.Lists; 
    using System.ComponentModel; 
     
    namespace Telerik.Sitefinity.Samples 
        public class ListsDisplayEx : ListDisplay 
        { 
            /// <summary> 
            /// Summary description for ListsDisplayEx 
            /// </summary> 
            protected override void CreateChildControls() 
            { 
                ListManager manager = new ListManager(); 
                IList list = manager.GetListsByIds(base.ListsIds); 
                // 
                //do the list sorting here         
                // 
                base.CustomDataSource = list; 
                base.CreateChildControls(); 
            } 
            public override Type LocalizationAssemblyInfo 
            { 
                get 
                { 
                    return typeof(ListDisplay); 
                } 
                set 
                { 
                    base.LocalizationAssemblyInfo = value; 
                } 
            } 
            public override Type AssemblyInfo 
            { 
                get 
                { 
                    return typeof(ListDisplay); 
                } 
                set 
                { 
                    base.AssemblyInfo = value; 
                } 
            } 
        } 

    To register the custom control in Sitefinity, open the web.config file and define in the <toolboxControls>:
    <add name="Custom Lists Display" section="New" type="Telerik.Sitefinity.Samples.ListsDisplayEx, App_Code" /> 

    I hope this is helpful.

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Ben
    Ben avatar
    18 posts
    Registered:
    12 May 2008
    27 Jul 2009
    Link to this post
    Georgi,
       If I create a DLL with a method that returns a sorted IList<MyClass>, can I used that method as the CustomDataSource for an off the shelf ListDisplay?  I'll ensure that MyClass has Headline and Content properties.
       If I can, what are my steps?  I've tried creating a DLL, adding it as a reference in the project, but don't know the correct syntax to point to it declaratively.
       Thanks,
          Ben
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Jul 2009
    Link to this post
    Hello Ben,

    " I've tried creating a DLL, adding it as a reference in the project, but don't know the correct syntax to point to it declaratively."

    The example shows creating of a custom control that you can use instead of the Built it, since the control inherits from ListDisplay. To call it decoratively in a control template or page template you should register tab prefix, assembly and namespace to "ListsDisplayEx ". Then use the TagPrefix to declare the control and set its properties.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Ben
    Ben avatar
    18 posts
    Registered:
    12 May 2008
    29 Jul 2009
    Link to this post
    Ivan,
       So what you're saying is that I cannot use the Custom Data Source field in your built-in control to provide my own List<> datasource.  My only option is to inherit a control from the built-in and adjust the code.  Is that correct?  If so, what is the CustomDataSource declarative field for?
       Regards,
          Ben
  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    03 Aug 2009
    Link to this post
    Hello Ben,

    I think that you are on the right way. The thing you should do now - create a control which uses the classes you have created. Then place this control on the Sitefinity page, together with the ListsDisplay and tell the ListsDisplay to use the custom control for the data source.

    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
Register for webinar
6 posts, 0 answered