Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

The problem is in the gridview the date is displayed as mm/dd/yyyy 12:00:00 which not the desired format.

Posted on 2007-07-20
12
Medium Priority
?
201 Views
Last Modified: 2013-11-26
I have a pracetice ASPX page that I'm working on.  I have created a database that I connected through the connection dialog, the test connection gives me the data correctly.  The date is in mm/dd/yyyy format.  The problem is in the gridview the date is displayed as mm/dd/yyyy 12:00:00 which not the desired format.  How do I set the gridview format for this particular field?
0
Comment
Question by:Hiddenattractor
  • 5
  • 4
  • 3
12 Comments
 

Expert Comment

by:Stevishere
ID: 19535732
You can set the display format in the gridview.  From the GV smart tag, click on Edit Columns, click on the column  name (in the bottom left-hand window) that contains the date field you want to format, the properties for the column are displayed in the right panel, you can type in a format expression in the DataFormatString field.  Optionally, you can click the Convert to Template Field, then manage the format in each of the Item, Insert, Update templates.
0
 

Author Comment

by:Hiddenattractor
ID: 19536489
In the DateFormatSting I have put in "mm/dd/yyyy" and mm/dd/yyyy and neither of these worked is there some thing else I should try?
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 19537488
Have you tried to put {0:d} in DateFormatSting ?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 

Expert Comment

by:Stevishere
ID: 19537916
Good addition jpaulino.  That should do it.
0
 

Author Comment

by:Hiddenattractor
ID: 19538211
I tried {0:d} ,"{0:d}" , {0:c}, and "{0:c}" and no change.  the item is still 7/19/07 12:00:00 AM when it should be just 7/19/07 like it is returned in the test connection.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 19538218
Can you post your code ?
0
 

Expert Comment

by:Stevishere
ID: 19538261
Try this: (\d{1,2}\/\d{1,2}\/\d{4})
0
 

Expert Comment

by:Stevishere
ID: 19538287
This is a good resource for expression codes:
http://regexlib.com
0
 

Author Comment

by:Hiddenattractor
ID: 19538384
Steveishere: I tried your string (\d{1,2}\/\d{1,2}\/\d{4}) and got an error rendering control.
Ipaulino: this is the section of code that holds the DataFormatString, here is the{0:d} that did not work. it is about the 6th line down.


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="messageID"
                    DataSourceID="SqlDataSource1">
                    <Columns>
                        <asp:BoundField DataField="date" HeaderText="date"
                            SortExpression="date" DataFormatString="{0:d}" />
                        <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
                        <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
                        <asp:BoundField DataField="messageText" HeaderText="messageText" SortExpression="messageText" />
                    </Columns>
                </asp:GridView>
0
 

Expert Comment

by:Stevishere
ID: 19538406
My bad. The parenthesis should not be used.
How about:
SortExpression="date" DataFormatString="\d{1,2}\/\d{1,2}\/\d{4}" />
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 19538472
Try to set the HtmlEncode = False ...
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 2000 total points
ID: 19538526
... and use your custom format!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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 Month11 days, 16 hours left to enroll

564 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