gridview.boundfield.dataformatstring doesn't work

Discussion in 'ASP .Net Web Controls' started by Abraham Andres Luna, Nov 30, 2005.

  1. 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
    Abraham Andres Luna, Nov 30, 2005
    #1
    1. Advertising

  2. 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"
    <> wrote:

    >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
    >
    Ing. Winkler Bernhard, Dec 2, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    2,808
  2. yefei

    BoundField and DataFormatString

    yefei, Mar 28, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    4,893
    yefei
    Mar 28, 2006
  3. Jimmy J.
    Replies:
    1
    Views:
    386
    Mark Rae
    Jan 10, 2007
  4. Replies:
    2
    Views:
    1,179
  5. TS
    Replies:
    3
    Views:
    992
    Phil H
    Dec 22, 2007
Loading...

Share This Page