Hey amative,
You should simply get into the habit of creating DropDownLists with a default "empty" value. Empty isn't really the term I would use, but it simply means that the selection of this value can be used in validation and it gives the user an idea as to what the dropdownlist will do for them.
Create your DropDownList with the following properties:
AppendDataBountItems = true
AutoPostBack = true
DataSourceID = {your datasource name}
DataTextField = {your text column}
DataValueField = {your value column}
Now, immediately add a new item to the dropdownlist (in the gui is fine)... The item should have the following values:
Enabled = true
Selected = true
Text = "Please select a value"
Value = 0
Note that I do not leave the Value property blank; this will not stay blank during the process of building the website... somehow VS.NET 2005 gets the idea that the Value if blank should be changed to the Text value. So I use ZERO (0) as my value since I know that my datasource will not contain a ZERO value. Change it to "NOTHING" or something if you need to.
What all this will do for you is allow your DataSource to append to the dropdownlist all of the values. It also allows you to set validation in your form. If I use ZERO for the value of my DataValueField I can use a rangevalidator to specifiy the validation fails if not > 0. Now your selection events will work fine, and you can even check for that value=0 to hide or show other form elements.
protected void ddl_SelectedIndexChanged(object sender, EvenArgs e)
{
if (ddl.SelectedValue !- "0")
{
btnNew.Enabled = true;
formviewUserControls.DefaultMode = FormViewMode.ReadOnly;
}
else
{
btnNew.Enabled = true;
}
}
Wil