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

Forums / Developing with Sitefinity / GallerySelector Error

GallerySelector Error

3 posts, 1 answered
  1. Roman
    Roman avatar
    20 posts
    Registered:
    20 Jan 2009
    18 Nov 2009
    Link to this post
    Hi

    I wanted to use the GallerySelector in one of my custom controls. According to the documentation the GallerySelector Class implements IWebUITypeEditor. Still, for the following code I get the following error:
     
        //imageGallery selector  
        [WebEditor("Telerik.Libraries.WebControls.GallerySelector, Telerik.Libraries")] 
        public string SelectImageGallery 
        { 
            get 
            { return this.imagegallery; } 
            set 
            { this.imagegallery = value; } 
        } 

    The error I got...
    Translation: GallerySelector cannot be converted to IWebUITypeEditor.

    Thanks in advance for your help :)

    Best
    Roman
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    18 Nov 2009
    Link to this post
    Hi Roman,

    GallerySelector inherits from ValueSelector<Guid> and  it is used only internally from LibraryService - Web Service. You need to create a simple custom web editor that inherits from WebUITypeEditor<string>. I develop a sample code for you. You only need to create a template for the selector.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Cms.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI;
    using Telerik.Cms;
    using Telerik.Libraries;
    using Telerik.Framework.Web;
    using System.Collections;
    using Telerik.Web.UI;
     
    /// <summary>
    /// Summary description for GallerySelectorCustom
    /// </summary>
    public class GallerySelectorCustom : WebUITypeEditor<string>
    {
        public GallerySelectorCustom()
        {
     
        }
     
        public override string Value
        {
            get
            {  
                object obj = this.ViewState["GalleryID"];
                if (obj == null)
                    return string.Empty;
                return (string)obj;
            }
            set
            {
                this.ViewState["GalleryID"] = value;
            }
        }
                 //CREATE A TEMPLATE FOR THE SELECTOR
        public string Templte
        {
            get
            {
                object o = this.ViewState["Template"];
                if (o == null)
                    return "~/CustomControls/SelectorTemplate.ascx";
                return (string)o;
            }
            set
            {
                this.ViewState["Template"] = value;
            }
        }
     
     
        protected virtual RadComboBox ComboBox
        {
            get { return this.Controls[0].FindControl("RadComboBox1") as RadComboBox; }
        }
     
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
     
            this.manager = new LibraryManager();
            this.template = ControlUtils.GetTemplate<GalleryTemplate>(this.Templte);
            IList AllLibraries = manager.GetAllLibraries();
            ComboBox.DataSource = AllLibraries;
            ComboBox.DataTextField = "Name";
            ComboBox.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(ComboBox_SelectedIndexChanged);
            ComboBox.DataBind();
        }
     
        void ComboBox_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            this.Value = ComboBox.SelectedItem.Value;
        }
     
     
        public class GalleryTemplate : ITemplate
        {
            public void InstantiateIn(Control container)
            {
            }
        }
     
        private ITemplate template;
        private LibraryManager manager;
    }


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. Roman
    Roman avatar
    20 posts
    Registered:
    20 Jan 2009
    19 Nov 2009
    Link to this post
    Wow thanks, very kind :)

    I'll try it out as soon as possible.

    Many thanks
    Best
    Roman
Register for webinar
3 posts, 1 answered