GridView row background color
How to change background color of a desired row?
I tried something like that:
protected void Button1_Click(object sender, EventArgs e)
{
GridViewMain.Rows[1].BackColor = System.Drawing.Color.Red;
}
but it doesn`t work :(
Thank you very much for any help in advance
[326 byte] By [
Martinez] at [2007-11-20 6:59:48]

# 1 Re: GridView row background color
check this link out
http://gridviewguy.com/ArticleDetails.aspx?articleID=172
that guy has several examples on how to change properties of the GridView and its rows. His example uses mouse over but you can adjust it to suit a click.
You have to use GridViewRowEventArgs e and e becomes the GridViewRow, then you can set e.BackColor to whatever you want
hth,
mcm
mcmcom at 2007-11-9 11:53:01 >

# 2 Re: GridView row background color
Thank you, but the problem is that I don`t want to use any event. I just want to loop all rows and set the color property of each row that meets the specific criteria.
For example:
if(myGridView.Rows[i].NumberOfCars == 2)
{
myGridView.Rows[i].BackColor = Color.Red
}
# 3 Re: GridView row background color
I also tried something like that:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex==1)
e.Row.BackColor = System.Drawing.Color.Red;
}
but it didn`t work at all :(
Because I did and it did not work. I checked under debug that it gets to the vital line:
e.Row.BackColor = System.Drawing.Color.Red;
but I still can`t see any difference - all rows are white.
# 4 Re: GridView row background color
use the RowDataBound Event of the gridview you can loop through all items there and set any color you want.
heres a good example
http://mikemalloy.wordpress.com/2007/02/15/change-gridview-row-color/
hth,
mcm
mcmcom at 2007-11-9 11:55:55 >

# 5 Re: GridView row background color
Thank you very much!
This unfortunatelly doesn`t wanna work on my page :( I set all themes and csss off and I still can`t c any difference.
# 6 Re: GridView row background color
Martinez,
Follow this link: http://www.google.ca/search?hl=en&q=GridView+%2B+Change+Row+Back+Color&meta=
there are literally dozens of examples of how to do this EXACTLY. I have supplied you with two, its very hard to help you out when you just say that it doesnt want to work. I suggest you carefully read the tutorials and perhaps create a TEST page with NO css or themes and test it there first. if that works then merge it with your existing page.
mcm
mcmcom at 2007-11-9 11:58:04 >
