Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

.net 2.0 format date string in grid view

Posted on 2006-10-23
4
Medium Priority
?
295 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 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

610 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