Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to change the color of the cell in Grid View Color
gridview cell if same values of that cell.

Please provide the code for the same.

Thank you

Rps
Posted

C#
for (int i = 0; i < GridView1.Rows.Count-1; i++)
       {
           for (int j = 0; j < GridView1.Rows[i].Cells.Count-1; j++)
           {
               if (GridView1.Rows[i].Cells[j]!=null)
               {
                   GridView1.Rows[i].Cells[j].BackColor = "Pink";
               }
           }
       }


This Will Help You any ways
You can call this where Ever Your Logic Fits..
Happy COdInG:)
 
Share this answer
 
Comments
rosren 6-Dec-12 6:20am    
this is not working,,plse helpmeee???
rosren 6-Dec-12 6:22am    
this is my code:: public bool validgrid() { if (btnSave.Text.ToLower() == "save" || btnSave.Text.ToLower() == "update") for (int i = 0; i < GrdvewHoldyDate.Rows.Count - 1; i++) { for (int j = 0; j < GrdvewHoldyDate.Rows[i].Cells.Count - 1; j++) { if (GrdvewHoldyDate.Rows[i].Cells[j] != null) { GrdvewHoldyDate.Rows[i].Cells[j].BackColor = System.Drawing.Color.Pink; } } }
Devang Vaja 6-Dec-12 6:27am    
the same values are where?in one row different columns?

or in multiple rows different columns?or anywhere in gridview?

have to put that logic under both loop
rosren 6-Dec-12 23:22pm    
gridview?multiple rows in differnt columns
Devang Vaja 7-Dec-12 0:16am    
Hey Gridview is taking Too much Time in cloloring & checking in the loop so i suggest u To make Your data View By dynamic html table.. and in that You check the condition..

HtmlTable TblView=new HtmlTable();HtmlTableRow Tr=new HtmlTableRow();

HtmlTableCell Tc=new HtmlTableCell();Tr=new HtmlTableRow();Tc=new HtmlTableCell();

Tc.InnerText=Ds.Tables[0].Rows[i]["ColumnName"]Tc.BgColor="Pink";

Tr.Cells.Add(Tc);...Your Logic..Tblview.Rows.Add(Tr);
hi.

this is my code, my value part is start from 3rd cell of each row in gridview.


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 3; i < e.Row.Cells.Count; i++)
{
Double ListPrice = Double.Parse(e.Row.Cells[i].Text);
if (ListPrice < 60)
{
e.Row.Cells[i].BackColor = System.Drawing.Color.Red;
}
else if (ListPrice > 60)
{
e.Row.Cells[i].BackColor = System.Drawing.Color.Green;
}
}
}
}
 
Share this answer
 
Comments
rosren 6-Dec-12 23:24pm    
i want to check same date exisitng or not?
I want to change the color of the cell in Grid View Color
gridview cell if same values of that cell.

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