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.Auto generate ASP.Net GridView Rows based on two Date range using C# and VB.Net<p>Hey <a class="username" rel="akhter">akhter</a>,</p> <p>Please 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;gvEmployees&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;EmployeeId&#34; HeaderText=&#34;EmployeeId&#34; /&gt; &lt;asp:BoundField DataField=&#34;Date&#34; HeaderText=&#34;Date&#34; /&gt; &lt;/Columns&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) { DateTime date1 = Convert.ToDateTime(&#34;10/12/2018&#34;); DateTime date2 = Convert.ToDateTime(&#34;10/13/2018&#34;); DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;EmployeeId&#34;, typeof(int)), new DataColumn(&#34;Date&#34;, typeof(string)) }); for (DateTime i = date1; i &lt;= date2; i = i.AddDays(1)) { for (int j = 1; j &lt;= 5; j++) { dt.Rows.Add(j, i.ToShortDateString()); } } this.gvEmployees.DataSource = dt; this.gvEmployees.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 Dim date1 As DateTime = Convert.ToDateTime(&#34;10/12/2018&#34;) Dim date2 As DateTime = Convert.ToDateTime(&#34;10/13/2018&#34;) Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() {New DataColumn(&#34;EmployeeId&#34;, GetType(Integer)), New DataColumn(&#34;Date&#34;, GetType(String))}) Dim i As DateTime = date1 While i &lt;= date2 For j As Integer = 1 To 5 dt.Rows.Add(j, i.ToShortDateString()) Next i = i.AddDays(1) End While Me.gvEmployees.DataSource = dt Me.gvEmployees.DataBind() End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/h2ha4NO.jpg" alt="" /></p>https://www.aspforums.net:443/Threads/415375/Auto-generate-ASPNet-GridView-Rows-based-on-two-Date-range-using-C-and-VBNet/https://www.aspforums.net:443/Threads/415375/Auto-generate-ASPNet-GridView-Rows-based-on-two-Date-range-using-C-and-VBNet/Tue, 11 Dec 2018 03:19:31 GMT