How do I set the date format in a webui datagrid column?

J

Jim H

I have a datagrid on a web form that is bound to a datatable that has a
column with datetime values. The default format is displaying the date and
time down to the second. I'd like to display the time down to the
millisecond as well as change the default for some other parts of the
datetime.
So instead of this:
MM/dd/yyyy hh:mm:ss

I'd like to display it like this:
MM/dd/yy HH:mm:ss:fff

Any ideas?

jim
 
S

Shiva

If you are using DataBinder.Eval(), pass the required formatting for the 3rd
parameter. In case of BoundColumn, use DataFormatString attribute.

HTH

I have a datagrid on a web form that is bound to a datatable that has a
column with datetime values. The default format is displaying the date and
time down to the second. I'd like to display the time down to the
millisecond as well as change the default for some other parts of the
datetime.
So instead of this:
MM/dd/yyyy hh:mm:ss

I'd like to display it like this:
MM/dd/yy HH:mm:ss:fff

Any ideas?

jim
 
J

Jim H

I'm using bound columns. The DataFormatString doesn't work.
I have this:
int liTimeStampIndex =
m_DataSet.Tables[lsTableName].Columns.IndexOf("time_stamp");
((BoundColumn)m_dgLogData.Columns[liTimeStampIndex]).DataFormatString =
"MM/dd/yy HH:mm:ss:fff";

The columns displays "MM/dd/yy HH:mm:ss:fff" instead of the time values now.

What am I missing?
jim
 
J

Jim H

Never mind I got it.
Needed "{0:MM/dd/yy HH:mm:ss:fff}"
Jim H said:
I'm using bound columns. The DataFormatString doesn't work.
I have this:
int liTimeStampIndex =
m_DataSet.Tables[lsTableName].Columns.IndexOf("time_stamp");
((BoundColumn)m_dgLogData.Columns[liTimeStampIndex]).DataFormatString =
"MM/dd/yy HH:mm:ss:fff";

The columns displays "MM/dd/yy HH:mm:ss:fff" instead of the time values
now.

What am I missing?
jim

Shiva said:
If you are using DataBinder.Eval(), pass the required formatting for the
3rd
parameter. In case of BoundColumn, use DataFormatString attribute.

HTH

I have a datagrid on a web form that is bound to a datatable that has a
column with datetime values. The default format is displaying the date
and
time down to the second. I'd like to display the time down to the
millisecond as well as change the default for some other parts of the
datetime.
So instead of this:
MM/dd/yyyy hh:mm:ss

I'd like to display it like this:
MM/dd/yy HH:mm:ss:fff

Any ideas?

jim
 

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

Top