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

Forums / Developing with Sitefinity / getting value from web editor

getting value from web editor

3 posts, 0 answered
  1. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    24 Feb 2011
    Link to this post
    Hi sir,

    I have a property(customer ID) in the web editor. which displays the ID of the customer which is retrieved from the custom control(using drop down which gets data from DB).My user control gets this ID and displays the customer data in the web page.

    Now I need to change this ID to a Customer Name in the property control so that user can identify which thing they selected using drop down box. How do i use 2 get/set property to set value different. one as name and other as ID.

    I used the following code to get the value:
        [Browsable(true)]
        [Category("Biography List Setting")]
        [WebEditor("BiographyPageSelector, App_Code")]
        public string BiographyID
        {
            get { return this.strBioID; }
            set { this.strBioID = value; }
        }

        string strBioID = "1";



    I used the following code to get all customer data from DB
    public class BiographyPageSelector : WebUITypeEditor<string>
    {
        private DropDownList BiographyDDL = null;
        private string _Value = null;
        public BiographyPageSelector()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public override string Value
        {
            get { return _Value; }
            set { _Value = value; }
        }

        protected override void CreateChildControls()
        {
            Controls.Clear();
            Controls.Add(new LiteralControl("Select People: "));
            BiographyDDL = new DropDownList();
            BiographyDDL.Style.Add("Width", "350px");
            BiographyDDL.SelectedIndexChanged += new System.EventHandler(BiographyDDL_SelectIndexChanged);

            DataTable dt = Library.ListBiography(null);
            if (dt.Rows.Count > 0)
            {
                BiographyDDL.DataSource = dt;
                BiographyDDL.DataTextField = "BiographyName";
                BiographyDDL.DataValueField = "BID";
                BiographyDDL.DataBind();
            }

            Controls.Add(BiographyDDL);

            if (BiographyDDL.Items.Count > 0)
                Value = BiographyDDL.SelectedItem.Value;
        }

        void BiographyDDL_SelectIndexChanged(object sender, System.EventArgs e)
        {
            Value = BiographyDDL.SelectedItem.Value;

        }
    }


    regards,
    sathya





  2. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    25 Feb 2011
    Link to this post
    I didn't got one reply from you...Do I want to make it very clear??
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    28 Feb 2011
    Link to this post
    Hello sathiyaseelan,

    You should get and set the value for the Value property from the ViewState. You should Get  the value of the Value property in CreateChildControls of your control ( this will give your string value) and re select the drop down - set SelectedItem when you open the selector, then when you click 'I'm done" of the WebUI type editor the values will be set again to Value property. Here is a sample

    public override string Value
       {
           get
           {
               var obj = (string)ViewState["selectedItem"];
              
                 
                   // get the selected item and add it as a value
                   // combo.SelectedItem
     
                
               return obj;
           }
           set
           {
               this.ViewState["selectedItem"] = value;
                
           }
       }


    Greetings,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Register for webinar
3 posts, 0 answered