I was trying to use the GridView.RowDataBound event to change the background color of the row in a GridView. But the data was missing. Here is what I trying:
void gvReport_RowDataBound(Object sender, GridViewRowEventArgs e){
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text.IndexOf(“Total:”) > 0)
e.Row.BackColor = System.Drawing.Color.FromArgb(247, 249, 223);
}
}
But my e.Row.Cells[1].Text had no data in it. I am binding the grid in code so maybe that is why the grid would not show any data. Here is what I did to get it to work:
protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e){
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView rowdata = (DataRowView)e.Row.DataItem;
if (rowdata[1].ToString().IndexOf(“Total:”) > 0)
e.Row.BackColor = System.Drawing.Color.FromArgb(247, 249, 223);
}
}
Hope this helps someone else.