
Signature
Regards,
Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
The custom is to do it in RowDataBound event although RowCreated or
PreRender can be used as well.
Here is an example:
protected void myGrid_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
switch (e.Row.RowState)
{
case DataControlRowState.Normal:
e.Row.BackColor = Color.Blue;
break;
case DataControlRowState.Alternate:
e.Row.BackColor = Color.Green;
break;
case DataControlRowState.Selected:
e.Row.BackColor = Color.Red;
break;
}
}
}

Signature
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
> Does anybody know of any examples on how to set both the row colour and
> the
> alternate row colour of a datagrid in code?
>
> I need to do this at runtime, probably in the page load event or something
> similar.
Phil Johnson - 11 Mar 2008 10:46 GMT
Thanks for your help again Eliyahu, much appreciated.

Signature
Regards,
Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
> The custom is to do it in RowDataBound event although RowCreated or
> PreRender can be used as well.
[quoted text clipped - 27 lines]
> > I need to do this at runtime, probably in the page load event or something
> > similar.