Dream Tech Blog

A person with no dream in life can never live a happy life.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

让下拉框中的每项有不同颜色的背景

Posted on 2004-01-27 17:28  Dream  阅读(1005)  评论(0)    收藏  举报
用HTML版上的控件,并把此DropDownList1转化成服务器控件使用.
定制的方式:
   DropDownList1.Items.Add(new ListItem("默认","white"));
   DropDownList1.Items.Add(new ListItem("红色","red"));
   DropDownList1.Items.Add(new ListItem("兰色","blue"));
   DropDownList1.Items.Add(new ListItem("紫色","SandyBrown"));
   DropDownList1.Items.Add(new ListItem("青色","Aqua"));
   DropDownList1.Items.Add(new ListItem("黄色","Yellow"));
   for (int i= 0 ;i < DropDownList1.Items.Count;i++)
   {
    DropDownList1.Items[i].Attributes.Add("style", "background-color:" + DropDownList1.Items[i].Value);
   }