VB.NET - Set the Selected Value of a DropDownList
Posted on 2007-04-04
VB.NET, ASP.NET. .NET 2.0, VB 2005
How do I set a DropDownList to show the correct selected value that I want. I have a dropdown list that gets populated with a SQLDataSource, but I need it to originally display the correct value, not just the first one returned from the select statement.
I have the values for DataTextField and DataValueField, but how do I set that to display on the dropdown.
For example, my dropdown has ID B33, B45, and B88 as the DataValueFields and Tim, Suzzie, and Cindy as the matching DataTextField.
It aways shows up with the first name, Tim.
How can I use a variable that contains the EmpName (or ID) and use it to set what is selected in the dropdown. None of these worked for me:
Me.ddlDistrict.SelectedValue = EmpName
Me.ddlDistrict.Value = EmpName