.........
if(!Page.IsPostBack)
{
BindTitleFontColor();//绑定字体颜色 }public void BindTitleFontColor()
{
DataTable dt=bll_XMLConfig.GetAllTitleFontColor();

this.drpTitleFontColor.DataSource=dt.DefaultView;
this.drpTitleFontColor.DataTextField="TextName";
this.drpTitleFontColor.DataValueField="TextVale";
this.drpTitleFontColor.DataBind(); for (int i =0;i < drpTitleFontColor.Items.Count ;i++ )
{  
this.drpTitleFontColor.Items[i].Attributes.Add("style","background-color:" + this.drpTitleFontColor.Items[i].Value);
}
}
附xml文件片断:
<?xml version="1.0" ?>
<TitleFontColors>
<TitleFontColor>
<TextName>background-color:#FFFFFF</TextName>
<TextVale>#FFFFFF</TextVale>
</TitleFontColor>
</TitleFontColors>
以上始终得不到下拉列表出现颜色效果?请大家帮我看看,感激涕零~

解决方案 »

  1.   

    附xml文件片断:  
    <?xml  version="1.0"  ?>  
    <TitleFontColors>  
               <TitleFontColor>  
                           <TextName>background-color:#FFFFFF</TextName>  
                           <TextVale>#FFFFFF</TextVale>  
               </TitleFontColor>  
              <TitleFontColor>
    <TextName>background-color:#008000</TextName>
    <TextVale>#008000</TextVale>
    </TitleFontColor>
    </TitleFontColors>  
      

  2.   

    你的方法我不会,,你可以不用这么做的,,,有一个专门的控件是 ColorDlg 用于添加颜色
      

  3.   

    http://www.c-sharpcorner.com/Code/2003/July/DropDownListBox.asp按照一个老外的例子,几年的了,应该是在1.1之前就能实现,试了半天,搞不出来
      

  4.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ddl.aspx.cs" Inherits="test_ddl" %><!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="DropDownList1"  runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                <asp:ListItem Value="0">#000000</asp:ListItem>
                <asp:ListItem Value="1">#FFFFFF</asp:ListItem>
                <asp:ListItem Value="2">#CCCCCC</asp:ListItem>
            </asp:DropDownList></div>
        </form>
    </body>
    </html> using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    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 test_ddl : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList1.Style.Value = "background-color:" + DropDownList1.SelectedItem.Text;
        }
    }
    我刚才花了一分钟时间随便变弄了个.你看看...希望给你点启发.
      

  5.   

    你的代码我看不懂,看我的:
    DataSet myds =new DataSet();myds.ReadXml(Server.MapPath("**.xml"));
    this.drpTitleFontColor.DataSource=myds.Tables[0];
    this.drpTitleFontColor.DataTextField="TextName";
    this.drpTitleFontColor.DataValueField="TextVale";
    this.drpTitleFontColor.DataBind();
      

  6.   

    asp.net 2.0之前默认无法实现的,必须重载Render方法,或者在客户端进行设置。
    asp.net2.0就可以了
      

  7.   

    这个方法可以的
    http://madgeek.com/Samples/DropDownList.cs.txt
      

  8.   

    感谢CSDN...感谢大哥大姐...感谢....
    结帐