如何基于列标题更改GridView列颜色

问题描述 投票:0回答:1

如何基于asp.net(vb.net)中的列标题更改GridView列颜色?例如,当列标题的文本以“ GT_”开头时,整个列将为红色,而标题为“ CF_”的则为绿色。

asp.net vb.net gridview colors header
1个回答
1
投票

使用像这样的行数据绑定事件:

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{    
  if (e.Row.RowType == DataControlRowType.DataRow)
   {
     DataRowView drv = (DataRowView)e.Row.DataItem;    
     for (int i = 0; i < drv.DataView.Table.Columns.Count; i++)
     {
       if (drv.DataView.Table.Columns[i].ColumnName.StartsWith("GT_"))    
        {
          e.Row.Cells[i].BackColor = System.Drawing.Color.LawnGreen;
          grdAdd.Columns[i].HeaderStyle.BackColor = System.Drawing.Color.Khaki;    
        }
     }
  }
}

此处输出output

© www.soinside.com 2019 - 2024. All rights reserved.