1. 程式人生 > >[ASP.NET] GridView 依條件更改某列背景顏色

[ASP.NET] GridView 依條件更改某列背景顏色

protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
{
  DataRowView drv = (DataRowView)e.Row.DataItem;

  if ((e.Row.RowType == DataControlRowType.DataRow) || (e.Row.RowType == DataControlRowType.Footer))
  {
    if (drv != null)
    {
       if (drv["arttype"].ToString().Trim() == "A")  //條件式
       {
          e.Row.Attributes.Add("style", "background-color:#f0d5b3"); //新增背景色屬性
       }
    }
   }
}



12        } 


13     } 


14    }