Solved

.net 2.0 format date string in grid view

Posted on 2006-10-23
4
286 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
forgot HtmlEncode=false
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

7 Experts available now in Live!

Get 1:1 Help Now