Change background color for asp:dropdownlist (VB.net)
<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub ddl1_Changed(Sender As Object, E As EventArgs)
ddl1.BackColor = System.Drawing.Color.FromName(ddl1.SelectedItem.Text)
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Writing Code that Fires when an Item is Selected in a DropDownList Control</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<BR><BR>
<asp:dropdownlist id="ddl1" autopostback="True" onselectedindexchanged="ddl1_Changed" runat="server">
<asp:listitem value="Bu">Blue</asp:listitem>
<asp:listitem value="Re">Red</asp:listitem>
<asp:listitem value="Gr">Green</asp:listitem>
<asp:listitem value="Pu" >Purple</asp:listitem>
<asp:listitem value="Ba">Black</asp:listitem>
</asp:dropdownlist>
</form>
</BODY>
</HTML>
Related examples in the same category