Solved

.net 2.0 format date string in grid view

Posted on 2006-10-23
4
288 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now