for (int i = 0; i < dataGridView1.Rows.Count; i++) { int x = (int)dataGridView1.Rows[i].Cells["number"].Value; //1、2、4、5、7 if (x == 1 || x == 2 || x == 4 || x == 5 || x == 7) { dataGridView1.Rows[i].Cells["Columns1"].Style.BackColor = Color.Red; } else { dataGridView1.Rows[i].Cells["Columns1"].Style.BackColor = Color.Blue; } }
<%# setString(eval("列名").Tostring())%>
后台
public void setString(str)
{
string strReturn="";
if(str=1||tr=2||tr=3||tr=4||tr=5||tr=7)
{
strRretu=<font color=red>" + str + "</font>"
}
if(str=0||tr=3||tr=6||tr=8||tr=9)
{
strRretu=<font color=blue>" + str + "</font>"
}
return strRretu;
}
不好意思呀,自己试着改了下没成功
能不能改好发到我邮箱
源文件下载地址: http://www.rayfile.com/files/4e865a38-f2c0-11de-8bd6-0014221b798a/
试试吧,很好玩的~~
if((Label)e.Item.Cell[2].Text=="1") //Cell2指第三列,单元格里没控件的话用Cells
(Label)e.Item.FindControl("LabelID").BackColor = "Red"; //单元格里有控件用FindControl()
else
(Label)e.Item.FindControl("LabelID").BackColor = "Red";
{
int x = (int)dataGridView1.Rows[i].Cells["number"].Value;
//1、2、4、5、7
if (x == 1 || x == 2 || x == 4 || x == 5 || x == 7)
{
dataGridView1.Rows[i].Cells["Columns1"].Style.BackColor = Color.Red;
}
else
{
dataGridView1.Rows[i].Cells["Columns1"].Style.BackColor = Color.Blue;
}
}
未处理 System.NullReferenceException
要怎么解决?