I want to change a particular row color of gridview based on some condition, I am using ASP.NET with c#. Thank you.
This method modifies both the back color (to dark red) and the text (to white) if a specific string ("TextToMatch") occurs in one of the columns:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells[8].Text.Equals("TextToMatch"))
{
e.Row.BackColor = System.Drawing.Color.DarkRed;
e.Row.ForeColor = System.Drawing.Color.White;
}
}
Or another way to write it:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells[8].Text.Equals("TextToMatch"))
{
e.Row.Attributes.CssStyle.Value = "background-color: DarkRed; color: White";
}
}