protected void Page_Load(object sender, EventArgs e)
{
EnsureItems();
Label1.Visible = false;
}
public override Object Value
{
get
{
return DropDownList1.SelectedValue;
}
set
{
EnsureItems();
DropDownList1.SelectedValue = System.Convert.ToString(value);
}
}
// check if some color is selected
public override bool IsValid()
{
if ((string) Value != "")
{
this.Label1.Visible = false;
return true;
}
else
{
this.Label1.Visible = true;
this.Label1.Text = "Please choose some color.";
return false;
}
}
// ensure that the DropDownList contains color options
public void EnsureItems()
{
if (DropDownList1.Items.Count == 0)
{
DropDownList1.Items.Add(new ListItem("(select color)", ""));
DropDownList1.Items.Add(new ListItem("red", "red"));
DropDownList1.Items.Add(new ListItem("green", "green"));
DropDownList1.Items.Add(new ListItem("blue", "blue"));
}
}
|