How to display shortdate format on a datagrid?

I

irene

Hi, I am displaying a datagrid on my webpage and it is linking to a
dataset. There is a datetime value from the dataset showing on the
webpage(datagrid) as full date format, like "10/27/2004 12:00:00 AM".
How can I convert them to shortdate format '10/27/2004'? Before I was
using sth like:

<asp:TemplateColumn HeaderText="Course Start Date">
<ItemTemplate>
<asp:Label text = '<%#
DateTime.Parse(Container.dataItem("CD_Date")).toString("D") %>' ID =
"lblStartDate" Runat =server/>
</ItemTemplate>
</asp:TemplateColumn>

But now I wonder whether there is an easy way to do it other than that
because the datagrid is linking to a dataset directly and I dont need
to add those Itemtemplate anymore.

Can anyone help me?

Thanks.

Irene
 
S

Scott Mitchell [MVP]

Irene, you can just use a BoundColumn with its DataFormatString set to
{0:d}. You can see an example here:
http://datawebcontrols.com/faqs/CustomizingAppearance/FormatDateTimeData.shtml

hth

Hi, I am displaying a datagrid on my webpage and it is linking to a
dataset. There is a datetime value from the dataset showing on the
webpage(datagrid) as full date format, like "10/27/2004 12:00:00 AM".
How can I convert them to shortdate format '10/27/2004'? Before I was
using sth like:

<asp:TemplateColumn HeaderText="Course Start Date">
<ItemTemplate>
<asp:Label text = '<%#
DateTime.Parse(Container.dataItem("CD_Date")).toString("D") %>' ID =
"lblStartDate" Runat =server/>
</ItemTemplate>
</asp:TemplateColumn>

But now I wonder whether there is an easy way to do it other than that
because the datagrid is linking to a dataset directly and I dont need
to add those Itemtemplate anymore.

Can anyone help me?

Thanks.

Irene


--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

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,743
Messages
2,569,477
Members
44,898
Latest member
BlairH7607

Latest Threads

Top