?
Solved

Format date in Gridview column using Visual Studio 2005

Posted on 2006-05-19
5
Medium Priority
?
802 Views
Last Modified: 2008-01-09
I have used the GridView menu->Edit Columns and set the  DataFormatString property for my column to be {0:dd/MM/yyyy}. However the formats I enter are not being used. Is there something else I have to do to get this to work? Here is the generated code:

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="GetResultSummary">
    <Columns>
        <asp:BoundField
        DataField="fldDate"
        HeaderText="Date"
        SortExpression="fldDate"
        DataFormatString="{0:dd/MM/yyyy}"
        />
    </Columns>
</asp:GridView>
0
Comment
Question by:cjmackenzie
5 Comments
 
LVL 6

Accepted Solution

by:
apb2 earned 500 total points
ID: 16717749
Hi try

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="GetResultSummary">
    <Columns>
        <asp:BoundField
        DataField="fldDate"
        HeaderText="Date"
        SortExpression="fldDate"
        DataFormatString="{0:dd/MM/yyyy}"
        HtmlEncode="false" />
    </Columns>
</asp:GridView>

 
0
 
LVL 5

Expert Comment

by:Argblat
ID: 16717753
did you try just

DataFormatString = "{0:d}"

-Mike
0
 

Author Comment

by:cjmackenzie
ID: 16717872
Yes. and "{0:t}". The format doesn't change. If I put "qwerty"{0:d} into the properties window, the gridview displays "qwerty"19/05/2006 00:00:00. Do I have to cast to a date or something? The field is a datetime type in SQL Server.

Colin
0
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 16717913
have you seen apb2's post?

they have used

HtmlEncode="false"

I believe that sorts your problem, as in the past that is what I was lacking.

:-)
0
 

Author Comment

by:cjmackenzie
ID: 16717939
You guys are all too quick for me. I replied to the 2nd post before seeing the 1st post, then I tried the solution suggested, it worked and before I can accept it someone else is helping. Fantastic :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

850 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