Epicmanagement
asked on
VB.NET - Set the Selected Value of a DropDownList
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.SelectedVal ue = EmpName
Me.ddlDistrict.Value = EmpName
Me.ddlDistrict.
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.SelectedVal
Me.ddlDistrict.Value = EmpName
Me.ddlDistrict.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
With the above code, subsitute combobox for dropdownlist. They function pretty much the same.
ASKER
What do I use instead of ListItem ?
This line gives me an error:
If ListItem.ID = strID Then
It says ID is not a member of ListItem ?
This line gives me an error:
If ListItem.ID = strID Then
It says ID is not a member of ListItem ?
ASKER
Nevermind, I got it. Thanks.