我有这个下拉列表。我需要在选择后显示颜色,如果可能的话我需要透明选择而不是"蓝色"当悬停在物品上时。
我需要这样的东西
<asp:DropDownList ID="ddlTimlineStatus" runat="server" Width="50px" CssClass="DropDownListStyle">
<asp:ListItem Value="G" style="background-color:green; color:green;"></asp:ListItem>
<asp:ListItem Value="Y" style="background-color:yellow; color:yellow;"></asp:ListItem>
<asp:ListItem Value="R" style="background-color:red; color:red;"></asp:ListItem>
</asp:DropDownList>
答案 0 :(得分:0)
如果在浏览器中呈现select
下拉列表,那么您可以更改选择的background
,但是使用css将无法更改突出显示颜色(当您悬停时)! (适用于Chrome和其他Webkit浏览器)
您可能希望将select
块更改为ul, li
构造。
答案 1 :(得分:0)
这就是我解决它的方式。 ASPX:
<asp:DropDownList ID="ddlOverallStatus" runat="server" AutoPostBack="true" OnLoad="ddlOverallStatus_Load"
CssClass="DropDownListStyleOverview" OnSelectedIndexChanged="ddlOverallStatus_SelectedIndexChanged" >
<asp:ListItem Value="0">Green</asp:ListItem>
<asp:ListItem Value="1">Yellow</asp:ListItem>
<asp:ListItem Value="2">Red</asp:ListItem>
</asp:DropDownList>
代码背后:
protected void ddlOverallStatus_Load(object sender, EventArgs e)
{
ddlOverallStatus = setColor(ddlOverallStatus, false);
}
protected void ddlOverallStatus_SelectedIndexChanged(object sender, EventArgs e)
{
ddlOverallStatus = setColor(ddlOverallStatus, true);
}
protected DropDownList setColor(DropDownList ddl, bool load)
{
if (load)
{
string s1 = ddl.SelectedItem.Text.ToString();
if (s1 == "Green")
ddl.BackColor = System.Drawing.Color.FromArgb(0,255,0);
else
ddl.BackColor = System.Drawing.Color.FromName(s1);
}
else
{
string s1 = ddl.SelectedItem.Text.ToString();
if (s1 == "Green")
{
ddl.BackColor = System.Drawing.Color.FromArgb(0, 255, 0);
ddl.ForeColor = System.Drawing.Color.FromArgb(0, 255, 0);
}
else
{
ddl.BackColor = System.Drawing.Color.FromName(s1);
ddl.ForeColor = System.Drawing.Color.FromName(s1);
}
}
return ddl;
}