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.Display only Date in ASP.Net GridView with AutoGenerateColumns True using C# and VB.Net<p>Hi <a class="username" rel="indradeo"> indradeo</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:GridView runat=&#34;server&#34; ID=&#34;gvDate&#34; AutoGenerateColumns=&#34;true&#34; OnRowDataBound=&#34;gvDate_RowDataBound&#34;&gt; &lt;/asp:GridView&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataTable dt = new DataTable(); dt.Columns.Add(&#34;DateTime&#34;); dt.Rows.Add(DateTime.Now.AddDays(-1)); dt.Rows.Add(DateTime.Now.AddDays(-2)); dt.Rows.Add(DateTime.Now.AddDays(-3)); dt.Rows.Add(DateTime.Now); gvDate.DataSource = dt; gvDate.DataBind(); } } protected void gvDate_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DateTime date = Convert.ToDateTime(e.Row.Cells[0].Text); e.Row.Cells[0].Text = date.ToString(&#34;dd-MM-yyyy&#34;); } }</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 DataTable = New DataTable() dt.Columns.Add(&#34;DateTime&#34;) dt.Rows.Add(DateTime.Now.AddDays(-1)) dt.Rows.Add(DateTime.Now.AddDays(-2)) dt.Rows.Add(DateTime.Now.AddDays(-3)) dt.Rows.Add(DateTime.Now) gvDate.DataSource = dt gvDate.DataBind() End If End Sub Protected Sub gvDate_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then Dim date1 As DateTime = Convert.ToDateTime(e.Row.Cells(0).Text) e.Row.Cells(0).Text = date1.ToString(&#34;dd-MM-yyyy&#34;) End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Output</strong></span></p> <form id="form1" action="CS.aspx" method="post"> <div class="aspNetHidden"><input id="__VIEWSTATE" name="__VIEWSTATE" type="hidden" value="/wEPDwULLTE4MDE3NTcxODcPZBYCAgMPZBYCAgEPPCsAEQIADxYEHgtfIURhdGFCb3VuZGceC18hSXRlbUNvdW50AgRkDBQrAAEWCB4ETmFtZQUIRGF0ZVRpbWUeCklzUmVhZE9ubHloHgRUeXBlGSsCHglEYXRhRmllbGQFCERhdGVUaW1lFgJmD2QWCgIBD2QWAmYPDxYCHgRUZXh0BQoxOC0wOC0yMDE5ZGQCAg9kFgJmDw8WAh8GBQoxNy0wOC0yMDE5ZGQCAw9kFgJmDw8WAh8GBQoxNi0wOC0yMDE5ZGQCBA9kFgJmDw8WAh8GBQoxOS0wOC0yMDE5ZGQCBQ8PFgIeB1Zpc2libGVoZGQYAQUGZ3ZEYXRlDzwrAAwBCAIBZIDqbeY8BmgLJCFEr4sX1ImdXWhzMTDC6d98HYd1w78j" /></div> <div> <div> <table id="gvDate" border="1"> <tbody> <tr><th scope="col">DateTime</th></tr> <tr> <td>18-08-2019</td> </tr> <tr> <td>17-08-2019</td> </tr> <tr> <td>16-08-2019</td> </tr> <tr> <td>19-08-2019</td> </tr> </tbody> </table> </div> </div> </form> <p>For more details refer below article.</p> <h1 class="header"><a title="Format DateTime column (field) in ASP.Net GridView with AutoGenerateColumns True'a" href="https://www.aspsnippets.com/Articles/Format-DateTime-column-field-in-ASPNet-GridView-with-AutoGenerateColumns-True.aspx">Format DateTime column (field) in ASP.Net GridView with AutoGenerateColumns True</a></h1>https://www.aspforums.net:443/Threads/145643/Display-only-Date-in-ASPNet-GridView-with-AutoGenerateColumns-True-using-C-and-VBNet/https://www.aspforums.net:443/Threads/145643/Display-only-Date-in-ASPNet-GridView-with-AutoGenerateColumns-True-using-C-and-VBNet/Mon, 19 Aug 2019 01:07:35 GMT