Solved

.net 2.0 format date string in grid view

Posted on 2006-10-23
4
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 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