Home All Groups Group Topic Archive Search About

gridview.boundfield.dataformatstring doesn't work

Author
30 Nov 2005 7:14 PM
Abraham Andres Luna
i tried the following code:

<asp:gridview id="gvRDK" runat="server" autogeneratecolumns="false">
<columns>
  <asp:Boundfield DataField="DateCreate" DataFormatString="DateCreate:
{0:d}" HeaderText="Date Created:" />
</columns>
</asp:gridview>

but i got the following output:

      Date Created:
      DateCreate: 1/1/1900 12:00:00 AM


why isn't it formatting as a short date?

i then tried to following code:

<asp:datagrid id="dgRDK" runat="server" autogeneratecolumns="false">
<columns>
  <asp:Boundcolumn DataField="DateCreate" DataFormatString="DateCreate:
{0:d}" HeaderText="BoundColumn" />
</columns>
</asp:datagrid>


and got the expected output:
      BoundColumn
      DateCreate: 1/1/1900


thank you for your help

Author
2 Dec 2005 2:13 AM
Ing. Winkler Bernhard
Hi Abraham,

And here comes the solution:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx

Add HtmlEncode="false" to the BoundField and all will work fine.


Bernhard Winkler


On Wed, 30 Nov 2005 14:14:46 -0500, "Abraham Andres Luna"
<a**@rdk.com> wrote:

Show quoteHide quote
>i tried the following code:
>
><asp:gridview id="gvRDK" runat="server" autogeneratecolumns="false">
> <columns>
>  <asp:Boundfield DataField="DateCreate" DataFormatString="DateCreate:
>{0:d}" HeaderText="Date Created:" />
> </columns>
></asp:gridview>
>
>but i got the following output:
>
>      Date Created:
>      DateCreate: 1/1/1900 12:00:00 AM
>
>
>why isn't it formatting as a short date?
>
>i then tried to following code:
>
><asp:datagrid id="dgRDK" runat="server" autogeneratecolumns="false">
> <columns>
>  <asp:Boundcolumn DataField="DateCreate" DataFormatString="DateCreate:
>{0:d}" HeaderText="BoundColumn" />
> </columns>
></asp:datagrid>
>
>
>and got the expected output:
>      BoundColumn
>      DateCreate: 1/1/1900
>
>
>thank you for your help
>