• ASP.NET改变checkboxlist选中项字体颜色


    @ 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"); 
    
                } 
            } 
        }
    
    
    
    
  • 相关阅读:
    info plist各个功能的详解
    打个测试包弄成连接供别人下载测试
    封装的数据请求加上风火轮的效果
    福大软工 · BETA 版冲刺前准备(团队)
    福大软工 · 第十一次作业
    Alpha 冲刺 (10/10)
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
    Alpha 冲刺 (7/10)
    Alpha 冲刺 (6/10)
  • 原文地址:https://www.cnblogs.com/xiaofengfeng/p/1938976.html
Copyright © 2020-2023  润新知