@ 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">
<asp:CheckBoxList ID="CheckBoxList1" runat="server" Width="728px" Height="40px" RepeatDirection="Horizontal">
<asp:ListItem Value="报纸">报纸</asp:ListItem>
<asp:ListItem>杂志</asp:ListItem>
<asp:ListItem>广播</asp:ListItem>
<asp:ListItem>电视</asp:ListItem>
<asp:ListItem>网络</asp:ListItem>
<asp:ListItem>亲朋介绍</asp:ListItem>
<asp:ListItem>招生简章</asp:ListItem>
<asp:ListItem>招生咨询会</asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" Width="107px" />
</form>
</body>
</html>
2.default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
{
if (this.CheckBoxList1.Items[i].Selected == true)
{
this.CheckBoxList1.Items[i].Text = this.CheckBoxList1.Items[i].Text.IndexOf("font") == -1 ? "<font color=‘red’>" + this.CheckBoxList1.Items[i].Text + "</font>" : this.CheckBoxList1.Items[i].Text.Replace("Black", "red");
}
else
{
this.CheckBoxList1.Items[i].Text =this.CheckBoxList1.Items[i].Text.IndexOf("font") == -1 ? "<font color=‘Black’>" + this.CheckBoxList1.Items[i].Text + "</font>" : this.CheckBoxList1.Items[i].Text.Replace("red", "Black");
}
}
}
ASP.NET改变checkboxlist选中项字体颜色
最新推荐文章于 2021-08-30 16:11:46 发布