c# - 不同颜色的gridview数据显示取决于文本

标签 c# .net asp.net gridview

我在 GridView 中显示学生出勤率。

我选择缺席为A,出席为P,离开为L。现在我想用红色显示A,用绿色显示P。

怎么样。请帮助我

最佳答案

请试试这个,让我知道你遇到了什么问题

protected void grdStudent_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        DataRow dr = ((DataRowView)e.Row.DataItem).Row;
        if (dr["Present"].ToString() == "A")
        {
            ((Label)e.Row.FindControl("yourLableID")).ForeColor= System.Drawing.Color.Red;
        //yourLableID is that lable in which you are showing A or P
        }
    }
}

关于c# - 不同颜色的gridview数据显示取决于文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2793215/

相关文章:

c# - TcpClient.GetStream().Read() 与 TcpClient.Client.Receive()

c# - 确定请求是 ASP.NET MVC 3 中的 PartialView 还是 AJAX 请求

c# - ASP.net 无法将文件附加为数据库

c# - 在 C# 中使用 ChromeDriver 单击包含特定类名的每个按钮

c# - 换行符在 MailMessage 的正文中不起作用

c# - 为什么我在通过 Postgresql 中的函数删除记录时收到 "out of range for bigint"错误?

c# - 定义委托(delegate)的两种方式

c# - 如何将 ContextMenu 放入 TabPage 的页眉

c# - Visual Basic 中的“Friend WithEvents”与 C# 中的 'private'

c# - Telerik RadEditor 对话框在随机元素中呈现