Hi Waghmare,
Check this example. Now please take its reference and correct your code.
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
DateTime startDate = Convert.ToDateTime("11-Aug-2020");
DateTime endDate = Convert.ToDateTime("25-Nov-2020");
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("Date");
while (startDate < endDate)
{
dt.Rows.Add(startDate.ToString("dd-MMM-yyyy"));
startDate = startDate.AddDays(5);
}
GridView gvDetails = new GridView();
gvDetails.DataSource = dt;
gvDetails.DataBind();
form1.Controls.Add(gvDetails);
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim startDate As DateTime = Convert.ToDateTime("11-Aug-2020")
Dim endDate As DateTime = Convert.ToDateTime("25-Nov-2020")
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.Add("Date")
While startDate < endDate
dt.Rows.Add(startDate.ToString("dd-MMM-yyyy"))
startDate = startDate.AddDays(5)
End While
Dim gvDetails As GridView = New GridView()
gvDetails.DataSource = dt
gvDetails.DataBind()
form1.Controls.Add(gvDetails)
End Sub
Output
Date |
11-Aug-2020 |
16-Aug-2020 |
21-Aug-2020 |
26-Aug-2020 |
31-Aug-2020 |
05-Sep-2020 |
10-Sep-2020 |
15-Sep-2020 |
20-Sep-2020 |
25-Sep-2020 |
30-Sep-2020 |
05-Oct-2020 |
10-Oct-2020 |
15-Oct-2020 |
20-Oct-2020 |
25-Oct-2020 |
30-Oct-2020 |
04-Nov-2020 |
09-Nov-2020 |
14-Nov-2020 |
19-Nov-2020 |
24-Nov-2020 |