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.
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.
Please suggest if there is any other way to accomplish this task.
Thanks in advance
Hi Robert,
Are you using web forms way of rendering dropdownList?
What version of Umbraco are you using?
Thanks,
Alex
is working on a reply...