Show Date only from DateTime in DataGrid

X

Xarky

Hi,
I am using the following code to display a datagrid on my page. Now
one of the columns is of type DateTime(DataField="myDate"). Now when
the datagrid is being shown, the date is given in the following
format: 4/30/2005 12:00:00AM

Now I require to show only the date, ie time is not required. What
code should I add to change the behaviour to that specified.


<asp:DataGrid id="dataGridNextSessions" runat="server" Height="240px"
Width="312px" BackColor="White" BorderWidth="1px" BorderStyle="None"
BorderColor="#CCCCCC" CellSpacing="2" CellPadding="3"
AllowSorting="True" AutoGenerateColumns="False"
DataKeyField="StudentID">
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#669999"></SelectedItemStyle>
<ItemStyle ForeColor="#000066"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#006699"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="StudentID" HeaderText="Student
ID"></asp:BoundColumn>
<asp:BoundColumn DataField="myDate" HeaderText="Session
Date"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" ForeColor="#000066"
BackColor="White" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>


Can someone help me out
Thanks in Advance
 
E

Elton W

Hi,

You can use DataFormatString to force it display in
specified format, e.g.

<asp:BoundColumn DataField="myDate" DataFormatString="{0:
MM/dd/yyyy}" HeaderText="Session Date"></asp:BoundColumn>


HTH

Elton
(e-mail address removed)



-----Original Message-----
Hi,
I am using the following code to display a datagrid on my page. Now
one of the columns is of type DateTime
(DataField="myDate"). Now when
 

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,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top