Hi,
I'm working on a ASP.NET web app, and have a question: in a code behind page (.aspx.cs), I need to assign a default value to a DDL, and have it displayed in the view (.aspx). I searched around and found some suggestions; but none worked for me so far.
This is what I have tried:
1) this.ddlYear.SelectedIndex = ddlYear.Items.IndexOf(ddlYear.Items.FindByValue(year)); // year is a string "2015", which is a valid option for ddlYear
Note: when I run dubugger, even though "year" has a valid value, the "this.ddlYear.SelectedIndex" is always "-1", that is the value for "Select", not the option for the actual year. Why? Isn't this line of code supposed to get the index?
2) if (!String.IsNullOrEmpty(country))
this.ddlCountry.Value = country; // country is ...
Go to the complete details ...