Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2007, 09:34 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Formatting Row Colours dependant on a field- FIXED

Hi,

I have been asked to create a page, that brings through data from a table into a gridview. (The easy bit :P)

Now for the difficult bit, they want each rows' background/text colours different dependant on text values of one of the attributes (which is in the gridview).

I haven't the foggiest how to do this, as I don't know how to access the data in the GridView, to then perform my check (which will be a basic nested if statement)

Any Ideas?
 
Old December 11th, 2007, 09:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well you can check the type of data that is entering into a row in the gridview datarow created event, and you can change the fore and back color, and everything else there...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old December 11th, 2007, 10:54 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How would I go about accessing the data in the row? I have been playing about but am having difficulty,

cheers

 
Old December 11th, 2007, 10:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Google to the rescue.. second hit.. try this:
http://weblogs.asp.net/hpreishuber/a...09/434889.aspx

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old December 11th, 2007, 11:28 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
 
public void GridView1_RowDataBound(Object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            String status = (String)((System.Data.DataRowView)e.Row.DataItem)["LastOpDesc"];

            if (status.Contains("Artwork"))
            {
                e.Row.BackColor = System.Drawing.Color.Green;
            }
            else if (status.Contains("Printing"))
            {
                e.Row.BackColor = System.Drawing.Color.Yellow;
            }
            else if (status.Contains("Finishing"))
            {
                e.Row.BackColor = System.Drawing.Color.Red;
            }
            else if (status.Contains("Guillotine Trim"))
            {
                e.Row.BackColor = System.Drawing.Color.Blue;
            }
            else e.Row.BackColor = System.Drawing.Color.Gray;
        }


    }
This is the code I am currently being used, but it doesn't apear to do anything at the moment, the grid is just its default background colour.

Any Clues?

 
Old December 11th, 2007, 12:47 PM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorted, forgot to reference the OnRowBound event in my gridview

 
Old December 13th, 2007, 05:59 AM
jomet
Guest
 
Posts: n/a
Default

Interesting topic

happy to read this..
cheers.


jomet.
---------------------------------------------
Once you start a working on something,
dont be afraid of failure and dont abandon it.
People who work sincerely are the happiest.





Similar Threads
Thread Thread Starter Forum Replies Last Post
write text file with fixed field length hugoscp Classic ASP Professional 0 June 27th, 2007 06:12 AM
ADODB.Field error '800a0bcd' - FIXED buddyz Classic ASP Databases 2 October 9th, 2006 05:52 PM
Help me on Fixed Field Length data files hossrad SQL Server DTS 3 January 29th, 2005 07:50 PM
Fixed row in datagrid JCP General .NET 1 January 13th, 2005 05:56 PM
how to set row height(fixed to 1 pixe) in DataGrid yoganand03 General .NET 1 May 5th, 2004 09:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.