I want to change the colour of row in grid view if a condition is met.
For example if the column Completed has the value = "yes"
I want the colour to be yellow.
othersise it could be white.
I need help regarding his.
Any help will be appreciated.
Regards
Loading

Siva SankarRank #9,790 · 202 reputationPosted Apr 29, 2015, 3:10 AM EDT
Please write the code as below...
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.DataRow)
{
//If Salary is less than 10000 than set the row Background Color to Cyan
if(Convert.ToInt32(e.Row.Cells[3].Text)<10000)
{
e.Row.BackColor = Color.Your_Color;
}
}
}
Manoj Kumar Mandal198 reputationPosted Apr 29, 2015, 3:12 AM EDT
Check this link http://stackoverflow.com/questions/5048762/change-gridview-row-color-based-on-condition-in-c-sharp
Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 29, 2015, 3:33 AM EDT
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { e.Row.Attributes.Add("style", "cursor:help;"); if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Alternate) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E56E94'"); e.Row.BackColor = Color.FromName("#E56E94"); } } else { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='gray'"); e.Row.BackColor = Color.FromName("gray"); } //e.Row.Cells[0].BackColor = Color.FromName("gray"); //e.Row.Cells[1].BackColor = Color.FromName("gray"); //e.Row.Cells[2].BackColor = Color.FromName("gray"); //e.Row.Cells[3].BackColor = Color.FromName("gray"); //e.Row.Cells[4].BackColor = Color.FromName("gray"); //e.Row.BorderWidth = 2; //e.Row.BorderColor = Color.FromName("#43C6DB"); } }Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 29, 2015, 3:34 AM EDT
protected void DrugGridView_RowDataBound(object sender, GridViewRowEventArgs e) { // To check condition on integer value if (Convert.ToInt16(DataBinder.Eval(e.Row.DataItem, "Dosage")) == 50) { e.Row.BackColor = System.Drawing.Color.Cyan; } }Pelumi Eluyera24 reputationPosted Apr 29, 2015, 3:54 AM EDT
I have tried the code youve given me exactly.
however i get an error.
Please see the attached picture.
Any help will be appreciated.