Hey akhter,
Please refer below sample.
HTML
<div>
From Date:
<asp:TextBox ID="TextBox1" runat="server" />
End Date:
<asp:TextBox runat="server" ID="TextBox2" />
<asp:Button ID="Button1" Text="Insert" runat="server" OnClick="Insert" />
<asp:GridView runat="server" ID="gvEmployees" />
</div>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Insert(object sender, EventArgs e)
{
string dateString = TextBox1.Text;
DateTime date1 = Convert.ToDateTime(dateString, System.Globalization.CultureInfo.GetCultureInfo("ur-PK").DateTimeFormat);
string dateString2 = TextBox2.Text;
DateTime date2 = Convert.ToDateTime(dateString2, System.Globalization.CultureInfo.GetCultureInfo("ur-PK").DateTimeFormat);
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("EmployeeId", typeof(int)), new DataColumn("Date", typeof(string)) });
for (int j = 1; j <= 2; j++)
{
for (DateTime i = date1; i <= date2; i = i.AddDays(1))
{
dt.Rows.Add(j, i.ToString("dd/MM/yyyy"));
}
}
this.gvEmployees.DataSource = dt;
this.gvEmployees.DataBind();
}
VB.Net
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("ur-PK").DateTimeFormat)
Dim dateString2 As String = TextBox2.Text
Dim date2 As DateTime = Convert.ToDateTime(dateString2, System.Globalization.CultureInfo.GetCultureInfo("ur-PK").DateTimeFormat)
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("EmployeeId", GetType(Integer)), New DataColumn("Date", GetType(String))})
For j As Integer = 1 To 2
Dim i As DateTime = date1
While i <= date2
dt.Rows.Add(j, i.ToString("dd/MM/yyyy"))
i = i.AddDays(1)
End While
Next
Me.gvEmployees.DataSource = dt
Me.gvEmployees.DataBind()
End Sub
Screeshot