November Happy Hour will be moved to Thursday December 5th.

Dropdownlist in Dynamic content Episerver 62

Vote:
 

Has anyone done a dropdownlist in dynamic content.  I am using the attribute to register the control as a dynamic content object but I am unclear how to render a dropdownlist in the dynamic content setting area.  Thanks in advance

#50803
May 12, 2011 17:56
Vote:
 

I'd use the PropertySelect or write my own custom property for this and just inherit from PropertyString and PropertySelectControlBase.

Eg:

[Serializable]
[PageDefinitionTypePlugIn]
public class PropertyWeekNumberDropDown : PropertyString
{
	public override IPropertyControl CreatePropertyControl()
	{
		return new PropertyWeekNumberDropDownControl();
	}
}


public class PropertyWeekNumberDropDownControl : PropertySelectControlBase
{
	protected override void SetupEditControls()
	{
		this.SetupDropDownList();
	}

	private void SetupDropDownList()
	{
		this.EditControl.DataSource = GetWeekNumbers;

		if (this.WeekNumberDropDown.Value != null)
		{
			this.EditControl.SelectedValue = this.WeekNumberDropDown.Value as string;
		}

		this.EditControl.DataBind();
	}

	private static string[] GetWeekNumbers
	{
		get
		{
			var weekNumbers = new string[54];
			weekNumbers[0] = "Velg uke";
			for (int i = 1; i <= 53; i++)
			{
				weekNumbers[i] = i.ToString();
			}

			return weekNumbers;
		}
	}

	public PropertyWeekNumberDropDown WeekNumberDropDown
	{
		get
		{
			return PropertyData as PropertyWeekNumberDropDown;
		}
	}
}

    

Then in your dynamic content user control:

public PropertyWeekNumberDropDown WeekNumber { get; set; }

    

#50804
Edited, May 12, 2011 19:45
Vote:
 

Thanks Frederik.  Ill give it a shot and see what happens.  Appreciate your quick response.

#50807
May 12, 2011 20:02
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.