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?
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.
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?
Have you tried to put {0:d} in DateFormatSting ?
Good addition jpaulino. That should do it.
ASKER
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
http://regexlib.com
ASKER
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="SqlDataSourc e1">
<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="messageTex t" />
</Columns>
</asp:GridView>
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
DataSourceID="SqlDataSourc
<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="messageTex
</Columns>
</asp:GridView>
My bad. The parenthesis should not be used.
How about:
SortExpression="date" DataFormatString="\d{1,2}\ /\d{1,2}\/ \d{4}" />
How about:
SortExpression="date" DataFormatString="\d{1,2}\
Try to set the HtmlEncode = False ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.