Link to home
Start Free TrialLog in
Avatar of Hiddenattractor
Hiddenattractor

asked on

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

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?
Avatar of Stevishere
Stevishere

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.
Avatar of Hiddenattractor

ASKER

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?
Avatar of Jorge Paulino
Have you tried to put {0:d} in DateFormatSting ?
Good addition jpaulino.  That should do it.
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.
Can you post your code ?
Try this: (\d{1,2}\/\d{1,2}\/\d{4})
This is a good resource for expression codes:
http://regexlib.com
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>
My bad. The parenthesis should not be used.
How about:
SortExpression="date" DataFormatString="\d{1,2}\/\d{1,2}\/\d{4}" />
Try to set the HtmlEncode = False ...
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial