我想只要表格里有等于1的单元格就变颜色,我现在只能改变指定列的颜色,高手帮我看下,谢谢了
int k = dss.Tables[0].Columns.Count;//定义表x有多少列
string[] shuju = new string[k];
for (int i1 = 0; i1 < k; i1++)
{
shuju[i1] = Convert.ToString(dss.Tables[0].Columns[i1].ColumnName);//原新表的字段名数组
}
foreach (string a6 in shuju)
{
for (int i = 0; i <= dss2.Tables[0].Rows.Count - 1; i++)
{
if (GridView2.Rows[i].Cells[0].Text == "b")
{
GridView2.Rows[i].Cells[0].Attributes.Add("bgcolor", "gray");
}
}
}
我想循环遍历,表里的每个单元格,判断,变颜色
我想要Cells[0]里不是只判断第一个,而是循环每个单元格判断
还是我自己研究出来了!!
for (int i = 0; i < e.Row.Cells.Count; i++)
{
if (e.Row.Cells[i].Text == "1")
{
e.Row.Cells[i].BackColor = System.Drawing.Color.Red;
string headtxt = GridView2.HeaderRow.Cells[i].Text;
string sxstr = headtxt.Substring(0, headtxt.IndexOf("_"));//取得列名
for (int j = 0; j < e.Row.Cells.Count; j++)
{
if (GridView2.HeaderRow.Cells[j].Text == sxstr)
{
e.Row.Cells[j].BackColor = System.Drawing.Color.Red;
}
}
}
}