how to display only date part in datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • agarwalsunitadhn
    New Member
    • Jan 2008
    • 82

    how to display only date part in datagrid

    hi..
    I am usingtemplate column in datagrid and in which i wint get the option of data expression field so that where i write the format.
    and i want to display only the date part not time.
    Thanks for your answer
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    To display only the date you need to use the property ToShortDateStri ng on your dataitem. Like this:

    <ItemTemplate >
    <asp:Label ID="lblTEST" Text='<%#Contai ner.DataItem("d ateTEST").Tosho rtDateString %>' runat="server" />
    </ItemTemplate>

    Hope this helps,

    Dr B

    Comment

    • agarwalsunitadhn
      New Member
      • Jan 2008
      • 82

      #3
      Originally posted by DrBunchman
      To display only the date you need to use the property ToShortDateStri ng on your dataitem. Like this:

      <ItemTemplate >
      <asp:Label ID="lblTEST" Text='<%#Contai ner.DataItem("d ateTEST").Tosho rtDateString %>' runat="server" />
      </ItemTemplate>

      Hope this helps,

      Dr B
      I got an error by writing this one. actually i used ms-access as backend

      Comment

      • agarwalsunitadhn
        New Member
        • Jan 2008
        • 82

        #4
        Originally posted by agarwalsunitadh n
        I got an error by writing this one. actually i used ms-access as backend
        This one properly works
        <asp:TemplateCo lumn HeaderText="Tim e">
        <ItemTemplate >
        <%# ((DateTime)Data Binder.Eval(Con tainer.DataItem , "Date")).ToShor tDateString() %>
        </ItemTemplate>
        </asp:TemplateCol umn>

        Thanks for giving me the suggestion.

        Comment

        Working...