conversion problem

B

Ben

Hi,

i want to change the forecolor of a label by choosing the color in a
dropdownlist like this:

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="red" Value="Drawing.Color.red"></asp:ListItem>
</asp:DropDownList>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Label1.ForeColor = CType(DropDownList1.SelectedValue, System.Drawing.Color)
End Sub

i get the error: "value ype string caanot converted to
System.Drawing.Color".
Why does the conversion not occur?
Thanks
Ben
 
G

Guest

Hi Ben,

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="red" Value="Red"/>
</asp:DropDownList>

Protected Sub Page_Load( _
ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load

Label1.ForeColor = System.Drawing.Color.FromName(DropDownList1.SelectedValue)

End Sub

BTW, you mixed casting with converting. To learn the difference see
http://www.codypowell.com/vlog/archives/000385.html

Hope this helps
 
B

Ben

Yes, thank you

Milosz Skalecki said:
Hi Ben,

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="red" Value="Red"/>
</asp:DropDownList>

Protected Sub Page_Load( _
ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load

Label1.ForeColor =
System.Drawing.Color.FromName(DropDownList1.SelectedValue)

End Sub

BTW, you mixed casting with converting. To learn the difference see
http://www.codypowell.com/vlog/archives/000385.html

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top