Home All Groups Group Topic Archive Search About

Show Date only from DateTime in DataGrid

Author
25 Apr 2005 3:14 PM
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

Author
25 Apr 2005 3:28 PM
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
elton_w***@hotmail.com




>-----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
>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>
Show quoteHide quote
><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
>.
>
Author
25 Apr 2005 3:46 PM
xarky d_best
Hi,
Thanks for your help.  Problem solved.



*** Sent via Developersdex http://www.developersdex.com ***
Author
24 May 2005 1:06 AM
linying
dshdhfkhkklghklgklkh;';kj'lkj;lkj;'l;';lkl;klk;kl;l;kk;lk;l;lk;lk