如何更改Gridview';基于特定单元格值的行颜色?Asp.net

如何更改Gridview';基于特定单元格值的行颜色?Asp.net,asp.net,gridview,colors,datatable,datatables,Asp.net,Gridview,Colors,Datatable,Datatables,我现在浏览了几十个网站和帖子,找不到任何“正确”的东西 我只想在Datatable/GridView中根据特定的单元格值用红色绘制一行 请帮帮我:( “最终表格”按此顺序包含以下内容: 邮件,姓名,姓氏,电话,身份证,租金,日志 刚刚注意到,当涉及到第二个if(这是真的)时,它还表示“索引超出范围” 主要问题是: 如何根据行的一个单元格值或仅根据行号为特定行设置不同的颜色? 希望很快能收到你们的来信 小心。在页面的加载方法中订阅网格的RowDataBound事件: this.GridView1

我现在浏览了几十个网站和帖子,找不到任何“正确”的东西

我只想在Datatable/GridView中根据特定的单元格值用红色绘制一行

请帮帮我:(

“最终表格”按此顺序包含以下内容: 邮件,姓名,姓氏,电话,身份证,租金,日志


刚刚注意到,当涉及到第二个if(这是真的)时,它还表示“索引超出范围”

主要问题是:

如何根据行的一个单元格值或仅根据行号为特定行设置不同的颜色?

希望很快能收到你们的来信


小心。

在页面的加载方法中订阅网格的
RowDataBound
事件:

this.GridView1.RowDataBound += GridView1_RowDataBound; 
当该行绑定到数据时,它将调用您的处理程序。以下是事件处理程序,您将在其中更改背景颜色:

private void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   //make sure it is not the header row
   if(e.Row.RowType == DataControlRowType.DataRow)
   {
      // whatever your condition
      if(e.Row.Cells[0].Text == "Whatever")
      {
         e.Row.BackColor = Drawing.Color.Red // This will make row back color red
      }
   }
}
this.GridView1.RowDataBound += GridView1_RowDataBound; 
private void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   //make sure it is not the header row
   if(e.Row.RowType == DataControlRowType.DataRow)
   {
      // whatever your condition
      if(e.Row.Cells[0].Text == "Whatever")
      {
         e.Row.BackColor = Drawing.Color.Red // This will make row back color red
      }
   }
}