Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 3rd, 2006, 01:31 AM
su su is offline
Authorized User
Join Date: Nov 2006
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cell/Font Color in DataGrid.


I am using C#.NET, Visual Web Developer 2005 and SQL Server 2000.

I am using Datagrid, SqlDataAdapter and Dataset for displaying data. One of the resultant column of the Datagrid is composed of concatenation of 2 columns in my database and is displayed like: <yes/no>, <no/no>, <yes/yes>, <no/yes>, <yes/cncld> , <no/cncld>.

This column can have one of these combination in the datagrid column. Now, I want to display all "yes" in green and all "no" in red and all "cncld" in black. so, essentially I want more than one color in my cell. I know that cell.Forecolor property can be applied to the entire cell making <yes/no> completely either green or red. But my task is applying more than one color in one cell.

Is there any way we can do this? I am able to capture the text "yes" , "no" and "cncld" as a string, but how do i then apply color? Should this be done in html file or the code behind file?

I am concatenating the two columns in html as:

<asp:Label runat="server" Text='<%# FormatSalesOPDName(DataBinder.Eval(Container, "DataItem.ORD_StatusUSASales"), DataBinder.Eval(Container, "DataItem.ORD_StatusUSAOPD")) %>' >

In code-behind:

  protected string FormatSalesOPDName(object ORD_StatusUSASales, object ORD_StatusUSAOPD)
    // Combine the names to get the Sales/OPD First format.
    return (string)ORD_StatusUSASales + "/" + (string)ORD_StatusUSAOPD;

Please HELP!
Reply With Quote
  #2 (permalink)  
Old December 3rd, 2006, 04:58 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

You can write another protected function that returns the appropriate colour based on the rules for combined yes, no and cancelled. Then have ForeColor='<%# GetForeColorForStatus(DataBinder.Eval(Container, "DataItem.ORD_StatusUSASales"), DataBinder.Eval(Container, "DataItem.ORD_StatusUSAOPD")) %>'


Joe (Microsoft MVP - XML)
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
back color of cell of datagrid rajessnit@gmail.com VB.NET 1 November 18th, 2006 03:28 AM
editing datagrid and changing cell color upon edit matoaka VS.NET 2002/2003 0 August 11th, 2006 11:04 AM
how to get font ,color,font size of text in win32 satishsatao Visual C++ 0 April 5th, 2006 05:05 AM
Font Color OzzyUltra Linux 1 October 22nd, 2004 10:01 AM
paint color cell in datagrid(c#) kobystud C# 0 August 1st, 2004 08:46 AM

All times are GMT -4. The time now is 06:49 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.