a have a gridview with datafield column which is bound to a datetime column.
i want the grid column to show the date when the day is first, like this: 24/2/2009

i tried the following format:


but the grid is still shows the date when the month is first.
where was i wrong ?

Recommended Answers

All 9 Replies

it is case sensitive, try this :


the total example is this :

Default.aspx :

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="PKID" DataSourceID="SqlDataSource1" 
        EmptyDataText="There are no data records to display.">
            <asp:BoundField DataField="PKID" HeaderText="PKID" ReadOnly="True" 
                SortExpression="PKID" />
            <asp:BoundField DataField="date" DataFormatString="{0:dd/MM/yyyy}" 
                HeaderText="date" SortExpression="date" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:denemeConnectionString1 %>" 
        DeleteCommand="DELETE FROM [Table1] WHERE [PKID] = @PKID" 
        InsertCommand="INSERT INTO [Table1] ([date]) VALUES (@date)" 
        ProviderName="<%$ ConnectionStrings:denemeConnectionString1.ProviderName %>" 
        SelectCommand="SELECT [PKID], [date] FROM [Table1]" 
        UpdateCommand="UPDATE [Table1] SET [date] = @date WHERE [PKID] = @PKID">
            <asp:Parameter Name="PKID" Type="Int32" />
            <asp:Parameter DbType="Date" Name="date" />
            <asp:Parameter DbType="Date" Name="date" />
            <asp:Parameter Name="PKID" Type="Int32" />

Default.aspx.cs :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e)


i tryed it the way you suggested with small letters:

it still doesnot work.

my full code line is:

<asp:BoundField DataField="date" DataFormatString="{:dd/MM/yyyy}"  HeaderText="date" />

The problem is the by default, the HtmlEncode property of the boundfield attribute is set to True. This helps prevent cross-site scripting attacks and malicious content from being displayed. Microsoft recommends that the HtmlEncode attribute be enabled whenever possible.

The problem is that if this field is enabled, you can not pass format information to the boundfield control. To solve this issue simply set HtmlEncode to false

Try this:

<asp:BoundField DataField="date" DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false"  HeaderText="date" />

well i tryed this and it still doesnot work.

Still not resolved??????????

just try this:


Works for me!

well i tryed this and it still doesnot work.


try this example:

<asp:BoundField DataField=”date_from” HeaderText=”DateApply” 
     HeaderStyle-Width =”350px” DataFormatString=”{0:MM/dd/yyyy}” HtmlEncode=”false”>

//—–another way

<asp:TemplateField HeaderText=”Date Submission” SortExpression=”DateSubmission”>
                    <asp:Label ID=”Label1″ runat=”server” Text=’<%# Bind(”DateSubmission”, “{0:dd/MM/yyyy}”) %>’></asp:Label>
                <ItemStyle HorizontalAlign=”Center” />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.