473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Datagrid - Formatting based on values

Hi All,

I wish to change the background colour and contents of a datagrid cell based
on the value of one of the columns on a per row basis. So, for example, if
column A's value is 1, column 2 should be red with 'No' written in it. If
column A's value is 0, column 2 should be green with 'Yes' written in it.

Can anyone advise how I could achieve this? (I know how to display/populate
the datagrid).

Thanks,
Simon.
Nov 19 '05 #1
2 1114
Simon,

Most flexible way is to use ItemDataBound event. Event handler gets
reference to an item which represents the grid row. You have access to the
item cells (row columns) and can get/set cells properties programmatically.

Eliyahu

"Simon Harris" <to***********@makes-you-fat.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi All,

I wish to change the background colour and contents of a datagrid cell based on the value of one of the columns on a per row basis. So, for example, if
column A's value is 1, column 2 should be red with 'No' written in it. If
column A's value is 0, column 2 should be green with 'Yes' written in it.

Can anyone advise how I could achieve this? (I know how to display/populate the datagrid).

Thanks,
Simon.

Nov 19 '05 #2
Thank you! :)

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...
Simon,

Most flexible way is to use ItemDataBound event. Event handler gets
reference to an item which represents the grid row. You have access to the
item cells (row columns) and can get/set cells properties
programmatically.

Eliyahu

"Simon Harris" <to***********@makes-you-fat.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi All,

I wish to change the background colour and contents of a datagrid cell

based
on the value of one of the columns on a per row basis. So, for example,
if
column A's value is 1, column 2 should be red with 'No' written in it. If
column A's value is 0, column 2 should be green with 'Yes' written in it.

Can anyone advise how I could achieve this? (I know how to

display/populate
the datagrid).

Thanks,
Simon.


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeff Cook | last post by:
Hi I have a DataGrid that I am using to display a .xml file (that has a schema in a .xsd), like this:- ds.ReadXmlSchema(sDataPath + "Data.xsd"); ds.ReadXml(sDataPath + "Data.xml",...
1
by: J.B | last post by:
I have a datagrid that will display different datasets, (it runs different sprocs based on a value in the querystring) but it will always return 6 columns. The 5th and 6th columns are always Date...
2
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
2
by: DraguVaso | last post by:
Hi, I'm looking for a nice way to format the cell of my datagrid according to some predefined 'rules'. I found a lot on the site of George shepherd, but it wasn't really what I was looking for:...
2
by: Starbuck | last post by:
Hi All Using VB.Net with a datagrid which shows a column called status - the values can be 0 to 6. Is there anyway of formatting this column show the numeric value is translated to a more...
4
by: steve | last post by:
Hi, First my apologies for double-posting but I am not sure wether this is a VB.Net or TSQL problem. I have the following problem: I generate a T-SQL string in order to fill my Dataset and...
2
by: Randall Parker | last post by:
Suppose you want to do either of these: A) Set display properties (e.g. color or boldness of text) of a cell based on a value of another cell in the same row. B) Set the display properties of...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.