Show Date only from DateTime in DataGrid

Discussion in 'ASP .Net Datagrid Control' started by Xarky, Apr 25, 2005.

  1. Xarky

    Xarky Guest

    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
     
    Xarky, Apr 25, 2005
    #1
    1. Advertising

  2. Xarky

    Elton W Guest

    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





    >-----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>
    ><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
    >.
    >
     
    Elton W, Apr 25, 2005
    #2
    1. Advertising

  3. Xarky

    xarky d_best Guest

    xarky d_best, Apr 25, 2005
    #3
  4. Xarky

    linying Guest

    dshdhfkhkklghklgklkh;';kj'lkj;lkj;'l;';lkl;klk;kl;l;kk;lk;l;lk;lk
     
    linying, May 24, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    768
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    606
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    446
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    379
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    806
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page