PC Review


Reply
Thread Tools Rate Thread

Datagrid - set row colour in code

 
 
Phil Johnson
Guest
Posts: n/a
 
      11th Mar 2008
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
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      11th Mar 2008
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" <(E-Mail Removed)> wrote in message
news:E413B49A-C826-4505-BC69-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Phil Johnson
Guest
Posts: n/a
 
      11th Mar 2008
Thanks for your help again Eliyahu, much appreciated.

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com


"Eliyahu Goldin" wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:E413B49A-C826-4505-BC69-(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Change Colour of Cell in datagrid satish Microsoft Dot NET 0 27th Mar 2007 01:11 PM
Every 5th Datagrid Line a different colour midgetgem Microsoft Dot NET Framework Forms 16 5th Dec 2005 10:21 PM
Datagrid - Changing row colour Simon Harris Microsoft ASP .NET 1 10th Feb 2005 08:36 AM
Code to change interior colour only if current interior colour is =?Utf-8?B?QmVTbWFydA==?= Microsoft Excel Programming 2 5th Oct 2004 12:06 AM
Colour datagrid scrollbars =?Utf-8?B?SmFjaw==?= Microsoft C# .NET 5 28th May 2004 02:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:08 AM.