OnDataItemBound event question

D

djc

one of the columns in my datagrid shows a date. I want to display dates <
the current date in red text. I believe I should be using the
OnDataItemBound event for this. Here is the problem I am having. When using
e.Item.Cells(4).Text I am getting the actual text displayed in the cell and
not the value from the database field. For example when this database field
is null the value of e.Item.Cells(4).Text ends up "&nbsp;". This alone is ok
because I can count on it and test for it in my code. My issue gets a little
more sticky because the condition to display the text in red or not is 2
part. Condition to display text in red in pseudo code: (DateColumn < Today
AND StatusColumn = "In Progress"). The StatusColumn is a template column and
so its e.Item.Cells(5).Text winds up with <span> tags and may or may not
also show an <img> tag. So how do I handle this? I need to use the actual
database field values for my comparison... how do I get to them?

any info is greatly appreciated.
 
E

Eliyahu Goldin

The easiest solution is to add a hidden column with original database value
and count on it rather then on it's templated presentation.

Eliyahu
 
D

djc

thanks for the input.

Eliyahu Goldin said:
The easiest solution is to add a hidden column with original database value
and count on it rather then on it's templated presentation.

Eliyahu

is
 
D

djc

I think I may have found what I needed... DataItem? e.DataItem("fieldName")?
I'm actually on my way out and won't be able to work on this today... can
anyone confirm that that is how I should access the underlying database data
from the OnDataBound event handler in a datagrid?

thanks again!
 
D

djc

I think I may have found what I needed... DataItem? e.DataItem("fieldName")?
I'm actually on my way out and won't be able to work on this today... can
anyone confirm that that is how I should access the underlying database data
from the OnDataBound event handler in a datagrid?

thanks again!
 
E

Eliyahu Goldin

For a BoundColumn you can use DataField property which gives you the name of
the field. You still need to find the record. The way I suggested is much
simpler. And you don't add anything to the internet traffic since hidden
columns don't render to client.

Eliyahu
 
D

djc

ok. Thanks again!

Eliyahu Goldin said:
For a BoundColumn you can use DataField property which gives you the name of
the field. You still need to find the record. The way I suggested is much
simpler. And you don't add anything to the internet traffic since hidden
columns don't render to client.

Eliyahu

is
 
M

Maddy

DataRowView r = (DataRowView) e.Item.DataItem;

djc said:
I think I may have found what I needed... DataItem? e.DataItem("fieldName")?
I'm actually on my way out and won't be able to work on this today... can
anyone confirm that that is how I should access the underlying database data
from the OnDataBound event handler in a datagrid?

thanks again!

dates
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top