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.Generate ASP.Net GridView Rows based on Date range defined in TextBox 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;div&gt; From Date: &lt;asp:TextBox ID=&#34;TextBox1&#34; runat=&#34;server&#34; /&gt; End Date: &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;TextBox2&#34; /&gt; &lt;asp:Button ID=&#34;Button1&#34; Text=&#34;Insert&#34; runat=&#34;server&#34; OnClick=&#34;Insert&#34; /&gt; &lt;asp:GridView runat=&#34;server&#34; ID=&#34;gvEmployees&#34; /&gt; &lt;/div&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 Insert(object sender, EventArgs e) { string dateString = TextBox1.Text; DateTime date1 = Convert.ToDateTime(dateString, System.Globalization.CultureInfo.GetCultureInfo(&#34;ur-PK&#34;).DateTimeFormat); string dateString2 = TextBox2.Text; DateTime date2 = Convert.ToDateTime(dateString2, System.Globalization.CultureInfo.GetCultureInfo(&#34;ur-PK&#34;).DateTimeFormat); DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;EmployeeId&#34;, typeof(int)), new DataColumn(&#34;Date&#34;, typeof(string)) }); for (int j = 1; j &lt;= 2; j++) { for (DateTime i = date1; i &lt;= date2; i = i.AddDays(1)) { dt.Rows.Add(j, i.ToString(&#34;dd/MM/yyyy&#34;)); } } this.gvEmployees.DataSource = dt; this.gvEmployees.DataBind(); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Insert(ByVal sender As Object, ByVal e As EventArgs) Dim dateString As String = TextBox1.Text Dim date1 As DateTime = Convert.ToDateTime(dateString, System.Globalization.CultureInfo.GetCultureInfo(&#34;ur-PK&#34;).DateTimeFormat) Dim dateString2 As String = TextBox2.Text Dim date2 As DateTime = Convert.ToDateTime(dateString2, System.Globalization.CultureInfo.GetCultureInfo(&#34;ur-PK&#34;).DateTimeFormat) 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))}) For j As Integer = 1 To 2 Dim i As DateTime = date1 While i &lt;= date2 dt.Rows.Add(j, i.ToString(&#34;dd/MM/yyyy&#34;)) i = i.AddDays(1) End While Next Me.gvEmployees.DataSource = dt Me.gvEmployees.DataBind() End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screeshot</strong></span></p> <p><img src="https://imgur.com/JQfjQv2.gif" alt="" width="245" height="431" /></p>https://www.aspforums.net:443/Threads/922038/Generate-ASPNet-GridView-Rows-based-on-Date-range-defined-in-TextBox-using-C-and-VBNet/https://www.aspforums.net:443/Threads/922038/Generate-ASPNet-GridView-Rows-based-on-Date-range-defined-in-TextBox-using-C-and-VBNet/Thu, 13 Dec 2018 03:19:54 GMT