protected void Page_Load(object sender, EventArgs e)
{
// Ensure drop down list options
EnsureItems();
}
/// <summary>
/// Gets or sets field value, color hexa code in this case.
/// </summary>
public override Object Value
{
get
{
return drpColor.SelectedValue;
}
set
{
// Ensure drop down list options
EnsureItems();
drpColor.SelectedValue = System.Convert.ToString(value);
}
}
/// <summary>
/// Returns an array of values of any other fields returned by the control.
/// </summary>
/// <returns>It returns an array where first dimension is attribute name and the second dimension is its value.</returns>
public override object[,] GetOtherValues()
{
object[,] array = new object[1, 2];
array[0, 0] = "ProductColor";
array[0, 1] = drpColor.SelectedItem.Text;
return array;
}
/// <summary>
/// Returns true if some color is selected. If no, it returns false and displays an error message.
/// </summary>
public override bool IsValid()
{
if ((string)Value != "")
{
return true;
}
else
{
// Set form control validation error message
this.ValidationError = "Please choose some color.";
return false;
}
}
/// <summary>
/// Ensures that the DropDownList contains color options.
/// </summary>
protected void EnsureItems()
{
if (drpColor.Items.Count == 0)
{
drpColor.Items.Add(new ListItem("(select color)", ""));
drpColor.Items.Add(new ListItem("red", "#FF0000"));
drpColor.Items.Add(new ListItem("green", "#00FF00"));
drpColor.Items.Add(new ListItem("blue", "#0000FF"));
}
}
|