Hi jmprateek,
Refer below code.
HTML
<asp:GridView ID="gvDates" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Si No" DataField="Id" />
<asp:BoundField HeaderText="Emi Date" DataField="EMIDate" />
</Columns>
</asp:GridView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[]
{
new System.Data.DataColumn("Id", typeof(int)),
new System.Data.DataColumn("EMIDate", typeof(string))
});
DateTime startDate = Convert.ToDateTime("03/20/2022");
DateTime endDate = Convert.ToDateTime("09/20/2022");
int i = 1;
while (startDate < endDate)
{
startDate = startDate.AddMonths(1);
dt.Rows.Add(i, startDate.ToString("dd-MM-yyyy"));
i++;
}
gvDates.DataSource = dt;
gvDates.DataBind();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.AddRange(New System.Data.DataColumn() {New System.Data.DataColumn("Id", GetType(Integer)), New System.Data.DataColumn("EMIDate", GetType(String))})
Dim startDate As DateTime = Convert.ToDateTime("03/20/2022")
Dim endDate As DateTime = Convert.ToDateTime("09/20/2022")
Dim i As Integer = 1
While startDate < endDate
startDate = startDate.AddMonths(1)
dt.Rows.Add(i, startDate.ToString("dd-MM-yyyy"))
i += 1
End While
gvDates.DataSource = dt
gvDates.DataBind()
End If
End Sub
Screenshot