[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Format Gridview

Posted on 2008-10-03
6
Medium Priority
?
925 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
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month17 days, 22 hours left to enroll

831 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