Click here to Skip to main content
16,022,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to change color of row of Gridview if Its first cell contain value
Total Corporate
,
Total SME
,
Grand Total


but is not applying it to gridview

What I have tried:

I have created stored procedure to Get values from database.
and bind that sp to gridview. it showing all values on gridview.

now to chang color of specific row i have written code in
GridView1_RowDataBound(
event of gridview as

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {


            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[0].Text == "Total Corporate")   // but here it showing text as null i.e ""
                {
                    e.Row.BackColor = System.Drawing.Color.Red;                 }
				}
}




but here it showing
text value as ""

if (e.Row.Cells[0].Text == "Total Corporate")  

and it is not applying color on Gridview Row
Posted
Updated 23-Aug-17 23:18pm

1 solution

I work MVC, so things are done differently. However, a quick Google Search (asp.net c# gridview conditional formatting)[^] turned up this accepted solution, so it should solve your problem:

* c# - How to implement conditional formatting in a GridView - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900