如何在gridview中设置行颜色。 [英] how to set row colors in gridview.
本文介绍了如何在gridview中设置行颜色。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
if (e.Row.RowType == DataControlRowType.DataRow)
{
int esal = int.Parse(e.Row.Cells[3].Text.ToString());
if (esal > 12000)
{
e.Row.ForeColor = System.Drawing.Color.Blue;
e.Row.BackColor = System.Drawing.Color.LightPink;
e.Row.Font.Italic = true;
}
else if (esal == 15000)
{
e.Row.ForeColor = System.Drawing.Color.Brown;
e.Row.BackColor = System.Drawing.Color.LightBlue;
e.Row.Font.Italic = true;
}
else
{
e.Row.ForeColor = System.Drawing.Color.White;
e.Row.BackColor = System.Drawing.Color.LightGreen;
e.Row.Font.Italic = true;
}
}
我试过这个,但是我得到了一个例外...输入字符串格式不正确...请帮助我
I tried this ,but i got an exception in this ...input string was not a correct format ...please help me
推荐答案
foreach (GridViewRow row in yourGridView.Rows) {
row.BackColor = Color.Green;
}
你的错误与颜色和所有东西无关。错误必须在你的代码的第一行。那就是:
You error has nothing to do with colors and all that stuff. Error must be at first line of your code.That is:
int esal = int.Parse(e.Row.Cells[3].Text.ToString());
将此替换为以下代码:
Replace this with below code:
int esal= string.IsNullOrEmpty(e.Row.Cells[3].Text) ? 0 : int.Parse(e.Row.Cells[3].Text);
问候......
Regards...
这篇关于如何在gridview中设置行颜色。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文