我想把Gridview某一列里最小的十个数值变色,我的代码如下,但老提示错误,找不出什么错误。或者有更好的写法?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
double[] a = new double[GridView1.Rows.Count]; \\定义一个数组
for (int i = 0; i <= GridView1.Rows.Count -1; i++)
{
a[i] =Convert.ToDouble(GridView1.Rows[i].Cells[4].Text); \\把GridView1的某列的值赋值到这个数组
}
Array.Sort(a); \\排序
for (int k = 0; k < 10; k++)
{
double b = a[k]; \\读出排在前10位的数
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
double c = Convert.ToDouble(GridView1.Rows[i].Cells[4].Text); \\查找每行的值
if (b == c) \\如果等于这个数的
{
GridView1.Rows[i].Cells[4].BackColor = System.Drawing.Color.Yellow;\\那一行变色。
}
}
}
}
一只斗牛犬