Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Datagrid - set row colour in code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Phil Johnson - 11 Mar 2008 10:05 GMT
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.
Signature

Regards,

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

Eliyahu Goldin - 11 Mar 2008 10:37 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.