Extending a DropDownList control
Posted
by Andrew Robinson
on Stack Overflow
See other posts from Stack Overflow
or by Andrew Robinson
Published on 2010-04-18T00:01:53Z
Indexed on
2010/04/18
0:13 UTC
Read the original article
Hit count: 564
ASP.NET
|custom-controls
I have a rather large application that has literally a hundred DDLs with Yes / No ListItems. In an attempt to same myself some time, I created a Custom Control that extends the standard DDL.
It all seems to work fine but I am having some issues when assigning the SelectedValue property in code where the selected value does not seem to have an affect on the control. I wonder if I should be adding my items during Init or PagePreLoad? Should I be calling base.OnInit before or after I add the list items? This mostly works but not 100%. (v3.5)
public class YesNoDropDownList : DropDownList
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!Page.IsPostBack)
{
base.Items.Add(new ListItem("Yes", "YES"));
base.Items.Add(new ListItem("No", "NO"));
}
}
}
© Stack Overflow or respective owner