后台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace yhx
{
public partial class ddl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Add_Choose();
}
}
/// <summary>
/// Add choose for DropDownList
/// And font color to red
/// </summary>
protected void Add_Choose()
{
ddl_yhx_choose.Items.Insert(0, new ListItem("请选择....", "0"));
ddl_yhx_choose.SelectedItem.Attributes.Add("style", "color:red");
}
}
}
前台:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddl_yhx_choose" runat="server">
<asp:ListItem Value="1">秦远东</asp:ListItem>
<asp:ListItem Value="2">于海翔</asp:ListItem>
<asp:ListItem Value="3">王伟健</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>