1

我在 asp.net 网页中有一个 gridview,并且该行的背景颜色根据特定单元格中的数据进行更改,但网格的第一行没有更改。为什么是这样?这是我用来更改颜色的代码:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
     if (e.Row.RowType == DataControlRowType.DataRow)
      {
        int StationStatus1 = Int32.Parse(GridView1.DataKeys[e.Row.RowIndex].Values[0].ToString());            
        foreach (GridViewRow row in GridView1.Rows)
        {
            switch (StationStatus1)
            {
                case 0:
                case 3:
                   e.Row.BackColor = System.Drawing.Color.Red;                        
                   break;                    
                case 12:                       
                    e.Row.BackColor = System.Drawing.Color.Blue;                        
                    break;
                default:
                    e.Row.BackColor = System.Drawing.Color.White;
                    break;

任何帮助将不胜感激。谢谢

4

0 回答 0