Solved

.net 2.0 format date string in grid view

Posted on 2006-10-23
4
290 Views
Last Modified: 2008-01-09
my dates display 10/17/2006 3:16:40 PM in grid view and I want to cut off time and display only 10/17/2006. How can it be done?


<asp:GridView ID="AllProjects" runat="server"
                AutoGenerateColumns = "False"
                AllowPaging  = "True"
                AllowSorting = "True"
                CellPadding  = "4"
                ForeColor    = "#333333" Width=800px
                onpageindexchanging ="CustomersGridView_PageIndexChanging"
                OnSorting="AllProjects_Sorting"
                OnRowCommand="AllProjects_RowCommand"
                >
    <Columns>
       <asp:BoundField    HeaderText="Date"         DataField="DateCreated"     SortExpression="DateCreated" />

    </Columns>
                  <HeaderStyle         BackColor="#333399" ForeColor="White" Font-Bold="True" />
                  <RowStyle            BackColor="#CCCCCC" />
                  <AlternatingRowStyle BackColor="White" />
                  <PagerStyle          BackColor="ControlDark" ForeColor="White" HorizontalAlign="Center" />
                  <Pagersettings       mode="NumericFirstLast" position="TopAndBottom" pagebuttoncount="5" />
              </asp:GridView>
0
Comment
Question by:TransBind
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:dfu23
ID: 17789445
DataFormatString:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx

<asp:BoundField
  HeaderText="Date"
  DataField="DateCreated"
  DataFormatString="{0:dd-MMM-yyyy}"
  SortExpression="DateCreated" />
0
 
LVL 14

Accepted Solution

by:
dfu23 earned 500 total points
ID: 17789454
Whoops, I didn't see the format you wanted at first ...

<asp:BoundField
  HeaderText="Date"
  DataField="DateCreated"
  DataFormatString="{0:dd/MM/yyyy}"
  SortExpression="DateCreated" />
0
 
LVL 7

Author Comment

by:TransBind
ID: 17789759
this syntax does not change the date format, is it possible that it does not change the format because I don't use sqldatasource object when I bind to gridview. I bind on a backend like so  

AllProjects.DataSource = dv; //dataview object
AllProjects.DataBind();
0
 
LVL 7

Author Comment

by:TransBind
ID: 17789814
forgot HtmlEncode=false
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question