<asp:DropDownList ID="ddlChangeColor" runat="server" Width="80">
                <asp:ListItem style="background-color: #008000;"></asp:ListItem>
                <asp:ListItem style='background-color: #800000'></asp:ListItem>
                <asp:ListItem style='background-color: #808000'></asp:ListItem>
                <asp:ListItem style='background-color: #000080'></asp:ListItem>
                <asp:ListItem style='background-color: #800080'></asp:ListItem>
                <asp:ListItem style='background-color: #808080'></asp:ListItem>
                <asp:ListItem style='background-color: #FFFF00'></asp:ListItem>
                <asp:ListItem style='background-color: #00FF00'></asp:ListItem>
                <asp:ListItem style='background-color: #00FFFF'></asp:ListItem>
                <asp:ListItem style='background-color: #FF00FF'></asp:ListItem>
                <asp:ListItem style='background-color: #FF0000'></asp:ListItem>
                <asp:ListItem style='background-color: #0000FF'></asp:ListItem>
                <asp:ListItem style='background-color: #008080'></asp:ListItem>
            </asp:DropDownList>    
这样是我想要的效果 ,每一行都是一种颜色。 。 但是我找不到他的索引,因为没有Value但是我要是加上Value 的话<asp:ListItem Value="#008000" style="background-color: #008000;"></asp:ListItem>
页面就会把我Value值显示出来。    谁帮忙解决下。 让页面显示的就是颜色。   我后台还能找到他的值

解决方案 »

  1.   

    ListItem li=ddlChangeColor.Items[0];
    li.
      

  2.   

    把value和text分开
    <asp:ListItem value="" style="background-color: #008000;">xxxx</asp:ListItem> 
      

  3.   

    dropDownList1.items.add(new ListItem(xx,xx));
      

  4.   

    2 3楼的 ,你们的都不对。。   2楼的, ,   你的页面不就显示XXX的吗? 我就要显示颜色。请看懂了在回答
      

  5.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:DropDownList ID="ddlChangeColor" runat="server" Width="80">
                    <asp:ListItem style="background-color: #008000;"> 1</asp:ListItem>
                </asp:DropDownList>
            </div>
        </form>
    </body>
    </html>using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(ddlChangeColor.Items[0].Attributes["style"].Split(new Char[]{':'})[1]);  
        }
    }
      

  6.   

    这很简单哦:在Page_Load事件中设置一下!!    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                for (int i = 0; i < ddlChangeColor.Items.Count; i++)
                {
                    ddlChangeColor.Items[i].Text = "";
                }
            }
        }