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;
}
}
}
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin http://usableasp.net
"Phil Johnson" <Ph*********@discussions.microsoft.comwrote in message
news:E4**********************************@microsof t.com...
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.
--
Regards,
Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com