Change ASP.Net GridView cell color using C# and VB.Net

ramco1917
 
on Jul 13, 2022 06:49 AM
341 Views

Hi

I have below code & i want if value in TextBox is A then color should be Red, If P color should be green.

protected void gr_RowDataBound(object sender, GridViewRowEventArgs e)
{
    try
    {
        if (e.Row.RowType != DataControlRowType.DataRow)
            return;
 
        e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Center;
 
        //e.Row.Cells[0].BackColor = ColorTranslator.FromHtml("#03a9f4");
        //e.Row.Cells[0].ForeColor = ColorTranslator.FromHtml("#fff");
    }
    catch (Exception ex)
    {
        Utility.SaveErrorLog(ex.Message, System.IO.Path.GetFileName(Request.Path), System.Reflection.MethodBase.GetCurrentMethod().Name, Convert.ToInt32(hdfLoginCode.Value));
        ShowMessage("Oops...", ex.Message, "error");
    }
}

Thanks

Download FREE API for Word, Excel and PDF in ASP.Net: Download