ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Custom DateTime format in GridView TemplateField columns in ASP.Net<p>Hi&nbsp;nauna,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:GridView ID=&#34;GridView1&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;False&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;Id&#34; HeaderText=&#34;Id&#34; /&gt; &lt;asp:TemplateField HeaderText=&#34;Date&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;Label2&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;date&#34;, &#34;{0:dddd, MMM dd, yyyy}&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt;</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.AddRange(new System.Data.DataColumn[] { new System.Data.DataColumn(&#34;Id&#34;, typeof(int)), new System.Data.DataColumn(&#34;date&#34;,typeof(DateTime)) }); dt.Rows.Add(1, new DateTime(2019, 08, 05)); GridView1.DataSource = dt; GridView1.DataBind(); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim dt As System.Data.DataTable = New System.Data.DataTable() dt.Columns.AddRange(New System.Data.DataColumn() { New System.Data.DataColumn(&#34;Id&#34;, GetType(Integer)), New System.Data.DataColumn(&#34;date&#34;, GetType(DateTime))}) dt.Rows.Add(1, New DateTime(2019, 8, 5)) GridView1.DataSource = dt GridView1.DataBind() End If End Sub</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <table id="GridView1" border="1" rules="all" cellspacing="0"> <tbody> <tr><th scope="col">Id</th><th scope="col">Date</th></tr> <tr> <td>1</td> <td><span id="GridView1_Label2_0">Monday, Aug 05, 2019</span></td> </tr> </tbody> </table> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/141320/Custom-DateTime-format-in-GridView-TemplateField-columns-in-ASPNet/https://www.aspforums.net:443/Threads/141320/Custom-DateTime-format-in-GridView-TemplateField-columns-in-ASPNet/Mon, 05 Aug 2019 03:18:59 GMT