Click here to Skip to main content
14,828,290 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have gridview which have empname,date of month as columns.Every cell has (A,P) value
i,e A for absent and P for present.I want to set the background color as red where cell value is A
till now i have done this but my prob still remain can you help me

C#
protected void PivotGridRowBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string val="";
                foreach (TableCell cell in e.Row.Cells)
                val = cell.Text;
                
                if(val=="A")
                {
                    
                   
                    
                }
                
            }
        }


[edit]Code block added[/edit]
Posted
Updated 11-Apr-14 22:35pm
v3

1 solution

try this. :)

C#
foreach (TableCell cell in e.Row.Cells)
           {
               string val = cell.Text;

               if (val == "A")
               {
                   cell.BackColor = System.Drawing.Color.Red;

               }
               else
               {

               .......
               }

           }


reference.. :)

Changing datagridview cell color based on condition[^]

Dynamically change GridView Row Background Color based on condition in ASP.Net using C# [^]
   
v2
Comments
Sandip Paul 491984 12-Apr-14 6:55am
   
but as my columns are days of a month so i can not fixed the index
Sandip Paul 491984 12-Apr-14 6:55am
   
but as my columns are days of a month so i can not fixed the index.
Nirav Prabtani 12-Apr-14 7:15am
   
see updated solution.. :) :)

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