Calling date conversion function before binding the date to a daragrid

S

Sanjeeb

I want to bind the date fteched from database to a datadrid. Date stored in data base is in UTC Time Format and I want to convert it to Local Time Format before binding it to the data grid. Now the challenege is not converting it to Local Time Format but to bind it to a datagrid. I can always have a function which can convert the UTC Format to Local Format. But, is there any datagrid event or any way in which that function can be called just before the date is bound to datagrid? The same issue seems pretty simple if I want the format converson which will be bound to any srver control like a text box or label. But, I don't know the way in which it can work for a datagrid.

Any idea

Thanks in advance
sanjeeb
 
A

Alvin Bruney

Have a look at the itemdatabound event handler. This event fires when each
row of data in the underlying source is being bound to the datagrid. So you
would be able to do
e.Item.Cells[3].Text = DateTime.Now.AddDays(-1).ToString("yyyyMM"));

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Sanjeeb said:
I want to bind the date fteched from database to a datadrid. Date stored
in data base is in UTC Time Format and I want to convert it to Local Time
Format before binding it to the data grid. Now the challenege is not
converting it to Local Time Format but to bind it to a datagrid. I can
always have a function which can convert the UTC Format to Local Format.
But, is there any datagrid event or any way in which that function can be
called just before the date is bound to datagrid? The same issue seems
pretty simple if I want the format converson which will be bound to any
srver control like a text box or label. But, I don't know the way in which
it can work for a datagrid.
 
C

CMA

or else you can format the date time just before take from the database like
this...

string lstrQueary = "SELECT Convert(varchar(10), SentDate,103)+' '+
Convert(varchar(10),Comment.SentDate,108) as formated_date FROM
UserReminder;

this will return the date as
from Convert(varchar(10), SentDate,103) >>> 18/01/2004
and from Convert(varchar(10),Comment.SentDate,108) >>> 10:24:30

so you'll get the output for formated_date is "18/01/2004 10:24:30"

hope this helps,
CMA

Sanjeeb said:
I want to bind the date fteched from database to a datadrid. Date stored
in data base is in UTC Time Format and I want to convert it to Local Time
Format before binding it to the data grid. Now the challenege is not
converting it to Local Time Format but to bind it to a datagrid. I can
always have a function which can convert the UTC Format to Local Format.
But, is there any datagrid event or any way in which that function can be
called just before the date is bound to datagrid? The same issue seems
pretty simple if I want the format converson which will be bound to any
srver control like a text box or label. But, I don't know the way in which
it can work for a datagrid.
 

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

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top