I have a dropdownlist box, from which a user makes a selection.
However, I am not able to retrieve the value of the SelectedItem in the code behind.
How can I get the value selected in the code behind?
if (ddlRegion.SelectedValue = "0")
{
Response.Write("<script>window.alert('Please select a region')</script>");
txtEmpID.Text = "";
return;
}
It looks like you’re trying to compare to 0, are you trying to check if the dropdownlist is at its default state (which is the first value)? If so, SelectedIndex is the property you want, and you want to compare to the integer literal
0, not the string"0". Also, it’s probably a copy/paste error as it doesn’t compile as is, but you want to compare equality with==, not make an assignment with=.