prezequias
prezequias

Reputation: 267

Display Dropdown values from checkbox in VB.Net

I need your help with the following situation: I have a dropdownlist as follows:

<asp:dropdownlist id="myvalues" runat="server">
<listitem value="Low">Low</listitem>
<listitem value="Medium">Medium</listitem>
<listitem value="High">High</listitem>
<listitem value="Super High">Super High</listitem>
</dropdownlist>

I need to call the above dropdown values from a checkbox as follows:

<asp:CheckBox ID="mybox" runat="server" Text="Click Me" Checked="true"/>

When I save the values, it works fine, but when I call the edit it display the first value only. I would like to bring the value saved, I also need to code in VB.Net I have tried the following but didn't work:

If mybox.checked = True Then
'myvalues.SelectedValue = true
 myvalues.Items(myvalues.Items.Count -1).Selected = True
else
'to do somethig here'
End If

The problem is that when I try to edit, it brigs only the first dropdown value, which is Low not the saved one. Can Anyone help me with matter? I'd like to thank in advance for your great support.

Upvotes: 0

Views: 537

Answers (1)

Bill Hall
Bill Hall

Reputation: 586

In your If statement you are doing this:

myvalues.SelectedValue = true

I think you meant:

myvalues.SelectedValue = "Super High"    'or whatever dropdown value you saved

Upvotes: 1

Related Questions