Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • robert 3 posts 73 karma points
    Aug 10, 2016 @ 07:15
    robert
    0

    How to create Dynamic dropdownlist

    Hello Guys,

    How can i create a dynamic populated dropdown list in Umbraco. I have used the "AbstractDataEditor" class but it's not working.

    Have a look at my code.

    public class DataType : AbstractDataEditor
        {
            private DropDownList control = new DropDownList();
    
            public override string DataTypeName
            {
                get { return "Dynamic job data dropdown"; }
            }
    
            public override Guid Id
            {
                get { return new Guid("833D755A-0A3C-4C06-8070-CA5E4BB9F68C"); }
            }
    
            public DataType()
            {
                base.RenderControl = control;
                control.Init += new EventHandler(control_Init);
                base.DataEditorControl.OnSave += new AbstractDataEditorControl.SaveEventHandler(DataEditorControl_OnSave);
            }
    
            void DataEditorControl_OnSave(EventArgs e)
            {
                base.Data.Value = control.SelectedValue;
            }
    
            //in this example, the dropdown values are stored in parent node
            void control_Init(object sender, EventArgs e)
            {
                var currentNodeId = Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);
                var parentNode = ApplicationContext.Current.Services.ContentService.GetParent(currentNodeId);
    
                for (int i = 0; i < 10; i++)
                {
                    control.Items.Insert(i, new ListItem(i.ToString(), i.ToString() + "_abhi"));
                }
    
                if (base.Data.Value != null)
                    control.SelectedValue = base.Data.Value.ToString();
            }
        }
    

    Please suggest if there is any other way to accomplish this task.

    Thanks in advance

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Aug 14, 2016 @ 11:17
    Alex Skrypnyk
    0

    Hi Robert,

    Are you using web forms way of rendering dropdownList?

    What version of Umbraco are you using?

    Thanks,

    Alex

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies