在单元格值条件格式 [英] Conditional formatting on cell value

查看:96
本文介绍了在单元格值条件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究条件格式为GridView的所有的地方,但我是新来的ASP.Net并不好受。这是我发现,最有意义给我的代码:

I've been researching conditional formatting for GridViews all over the place, but I am new to ASP.Net and having a hard time. This is the code that I've found that makes the most sense to me:

protected void GridviewRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        int CellValue = Convert.ToInt32(e.Row.Cells[2].Text);
        if (CellValue >= 0)
        {
            e.Row.Cells[2].BackColor = System.Drawing.Color.Green;
        }
        if (CellValue < 0)
        {
            e.Row.Cells[2].BackColor = System.Drawing.Color.Red;
        }
    }
}



GridView控件是非常简单:一个标题行,并与在每列的货币金额的标题下的一行三列。我只需要上第二行中的数据单元格,第三栏是绿色的,如果> = 0和红色如果< 0

The GridView is incredibly simple: a header row and three columns with one row under the header with a currency amount in each column. I just need the data cell on that second row, third column to be green if >=0 and red if <0.

我收到的格式不正确INT CellValue =行。

I am getting an incorrect format on the int CellValue = line.

推荐答案

尝试更换你的 INT CellValue = 行由地下1

Try replacing your int CellValue = line with below one

int CellValue = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Difference"));



参考:
http://www.johnchapman.name/asp-net-c-change-gridview-cell -background色为主,在价值/

http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx

这篇关于在单元格值条件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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