conversion problem

  • Thread starter Thread starter Ben
  • Start date Start date
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
 
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
 
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
 
Back
Top