如何动态更改gridview单元格文本颜色 [英] How to change gridview cell text color dynamically

查看:215
本文介绍了如何动态更改gridview单元格文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据我的逻辑更改网格视图单元格文本颜色。你可以帮我解决这个问题。

提前谢谢

I want to change the grid view cell text color based on my logic. Can you help me out to solve this problem.
Thanks in advance

推荐答案

这是一项非常简单的任务。我们可以使用RowDataBound事件处理程序。

This is very simple task. We can make use of the RowDataBound event handler.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[2].Text == "pass")
            {
                e.Row.Cells[2].ForeColor = System.Drawing.Color.Green;
            }
            else if (e.Row.Cells[2].Text == "Fail")
            {
                e.Row.Cells[2].ForeColor = System.Drawing.Color.Red;
            }
        }
    }





参考:在asp.net C#中的gridview中动态更改文本颜色



Refer: Dynamically change text color in gridview in asp.net C#


您还可以使用类或ID在jquery / javascript中操作html元素。所以按下按钮f12并选择你想要操作的元素来获取它的ID或类,然后使用jquery / javascript操作它。
You can also manipulate your html elements in jquery/javascript using classes or ID. So push button f12 and select the element you want to manipulate to get the its ID or class, then manipulate it using jquery/javascript.


这篇关于如何动态更改gridview单元格文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆