I want to set the selecteditem attribute for an ASP.Net dropdownlist control programmatically.
So I want to pass a value to the dropdownlist control to set the selected item where the item is equal to the passed value.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming the list is already data bound you can simply set the
SelectedValueproperty on your dropdown list.The value of the
myValuevariable would need to exist in the property specified within theDataValueFieldin your controls databinding.UPDATE:
If the value of
myValuedoesn’t exist as a value with the dropdown list options it will default to select the first option in the dropdown list.