Hi Shivashank,
Please refer below sample. It's working in both BoundField and TemplateField.
Database
For this sample I have used of NorthWind database that you can download using the link given below.
Download Northwind Database
HTML
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="OrderDate" HeaderText="OrderDate" ReadOnly="true" DataFormatString="{0:MM/dd/yyyy }"
HtmlEncode="false" />
<asp:BoundField DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField DataField="ShipCountry" HeaderText="ShipCountry" />
<asp:TemplateField HeaderText="ShippedDate">
<ItemTemplate>
<asp:Label ID="lblDate" Text='<%# Eval("ShippedDate", "{0:MM/dd/yyyy}") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespaces
C#
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 5 OrderDate, CustomerId, ShippedDate, ShipCountry FROM Orders", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
this.gvOrders.DataSource = dt;
this.gvOrders.DataBind();
}
}
}
}
}
Screenshot
