?
Solved

Format Gridview

Posted on 2008-10-03
6
Medium Priority
?
918 Views
Last Modified: 2013-12-17
I have a gridview which has a datetime column which displays dd/mm/yyy mm:hh:ss.

I would like to format the column in the gridview to show only dd/mm/yy is this possible?
0
Comment
Question by:Mr_Shaw
[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
  • 2
6 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22632440
You need to set a field HtmlEncode = false when you have a bound data column to a gridview. I created this sample  for you.

Notice the formatting applied on date fields -( DataFormatString="{0:d}" HtmlEncode=false)

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="OrderID"
            DataSourceID="Northwind">
            <Columns>
                <asp:BoundField DataField="OrderID" HeaderText="OrderID" InsertVisible="False" ReadOnly="True"
                    SortExpression="OrderID" />
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" SortExpression="CustomerID" />
                <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" SortExpression="EmployeeID" />
                <asp:BoundField DataField="OrderDate" HeaderText="OrderDate" SortExpression="OrderDate" DataFormatString="{0:d}" HtmlEncode=false />
                <asp:BoundField DataField="RequiredDate" HeaderText="RequiredDate" SortExpression="RequiredDate" DataFormatString="{0:d}" HtmlEncode=false />
                <asp:BoundField DataField="ShippedDate" HeaderText="ShippedDate" SortExpression="ShippedDate" DataFormatString="{0:d}" HtmlEncode=false />
            </Columns>
        </asp:GridView>


0
 
LVL 4

Expert Comment

by:sijishJohn
ID: 22632461
use this

<asp:boundfield datafield="datecolum" dataformatstring="{0:MM/dd/yy}" htmlencode="false" />
without the htmlencode attribute set to false you will get the time added as well
0
 

Author Comment

by:Mr_Shaw
ID: 22632509
I have used
<asp:boundfield datafield="datecolum" dataformatstring="{0:MM/dd/yy}" htmlencode="false" />

and I get the following error;

Warning 6 Element 'boundfield' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.
0
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 
LVL 4

Expert Comment

by:sijishJohn
ID: 22632568
please provide the html code of your gridview
0
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 2000 total points
ID: 22632572
.net is case sensitive use  this
<asp:BoundField DataField="datecolum" HeaderText="OrderDate" DataFormatString="{0:MM/dd/yy}" HtmlEncode=false />
0
 

Author Closing Comment

by:Mr_Shaw
ID: 31502699
thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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