下拉框选项

好奇都是要学的 2009-12-08 04:39:41
<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值显示出来。 谁帮忙解决下。 让页面显示的就是颜色。 我后台还能找到他的值
...全文
151 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
koukoujiayi 2009-12-08
  • 打赏
  • 举报
回复
这很简单哦:在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 = "";
}
}
}
  • 打赏
  • 举报
回复
6楼的, 你的页面不得显示1啊 , 7楼的没看懂
wartim 2009-12-08
  • 打赏
  • 举报
回复
<%@ 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]);
}
}
  • 打赏
  • 举报
回复
1楼的也不好使。 li.啥啊。
  • 打赏
  • 举报
回复
2 3楼的 ,你们的都不对。。 2楼的, , 你的页面不就显示XXX的吗? 我就要显示颜色。请看懂了在回答
PandaIT 2009-12-08
  • 打赏
  • 举报
回复
dropDownList1.items.add(new ListItem(xx,xx));
ivws_19 2009-12-08
  • 打赏
  • 举报
回复
把value和text分开
<asp:ListItem value="" style="background-color: #008000;">xxxx</asp:ListItem>
zetee 2009-12-08
  • 打赏
  • 举报
回复
ListItem li=ddlChangeColor.Items[0];
li.

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧