Hi ,
Check this
int GetDaysInMonth(int month, int year)
{
if (month < 1 || month > 12)
{
throw new System.ArgumentOutOfRangeException("month", month, "month mustbe between 1 and 12");
}
if (1 == month || 3 == month || 5 == month || 7 == month || 8 == month ||
10 == month || 12 == month)
{
return 31;
}
else if (2 == month)
{
if (0 == (year % 4))
{
if (0 == (year % 400))
{
return 29;
}
else if (0 == (year % 100))
{
return 28;
}
return 29;
}
return 28;
}
return 30;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
int days = GetDaysInMonth(Convert.ToInt32(DropDownList1.SelectedValue), Convert.ToInt32(DateTime.Now.Year));
DataTable myDT = new DataTable();
for (int i =0; i < days; i++)
{
DataColumn id = new DataColumn("id");
id.ColumnName = id + i.ToString();
id.DataType = System.Type.GetType("System.Int32");
myDT.Columns.Add(id);
}
for (int i = 1; i <= 1; i++)
{
DataRow dr = myDT.NewRow();
for (int ii = 0; ii < days; ii++)
{
dr[ii] = ii.ToString();
}
myDT.Rows.Add(dr);
}
GridView1.DataSource = myDT;
GridView1.DataBind();
}
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="1">jan</asp:ListItem>
<asp:ListItem Value="2">feb</asp:ListItem>
<asp:ListItem Value="3">mar</asp:ListItem>
<asp:ListItem Value="4">apr</asp:ListItem>
<asp:ListItem Value="5">may</asp:ListItem>
<asp:ListItem Value="6">jun</asp:ListItem>
<asp:ListItem Value="7">jul</asp:ListItem>
<asp:ListItem Value="8">aug</asp:ListItem>
<asp:ListItem Value="9">sep</asp:ListItem>
<asp:ListItem Value="10">oct</asp:ListItem>
<asp:ListItem Value="11">nov</asp:ListItem>
<asp:ListItem Value="12">dec</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" >
<Columns>
</Columns>
</asp:GridView>
</div>
Best Regards
M.Mitwalli