This way
HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function calculate_age(birth_month, birth_day, birth_year) {
var birth_month = document.getElementById("<%=ddlMonths.ClientID %>").value;
var birth_day = document.getElementById("<%=ddlDays.ClientID %>").value;
var birth_year = document.getElementById("<%=ddlYears.ClientID %>").value;
today_date = new Date();
today_year = today_date.getFullYear();
today_month = today_date.getMonth();
today_day = today_date.getDate();
age = today_year - birth_year;
if (today_month < (birth_month - 1)) {
age--;
}
if (((birth_month - 1) == today_month) && (today_day < birth_day)) {
age--;
}
alert('you are ' + age + 'yeas old');
}</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlYears" runat="server">
<asp:ListItem Text="2000" />
<asp:ListItem Text="2001" />
<asp:ListItem Text="2002" />
<asp:ListItem Text="2003" />
<asp:ListItem Text="2004" />
<asp:ListItem Text="2005" />
<asp:ListItem Text="2006" />
<asp:ListItem Text="2007" />
</asp:DropDownList>
<asp:DropDownList ID="ddlMonths" runat="server">
<asp:ListItem Text="1" />
<asp:ListItem Text="2" />
<asp:ListItem Text="3" />
<asp:ListItem Text="4" />
<asp:ListItem Text="5" />
<asp:ListItem Text="6" />
<asp:ListItem Text="7" />
<asp:ListItem Text="8" />
</asp:DropDownList>
<asp:DropDownList ID="ddlDays" runat="server">
</asp:DropDownList>
<asp:Button Text="Calculate" OnClientClick="calculate_age();" runat="server" />
</div>
</form>
</body>
</html>
C#:
This is for just adding days from 1 to 30.
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Day", typeof(int));
for (int i = 1; i < 31; i++)
{
dt.Rows.Add(i);
}
ddlDays.DataTextField = "Day";
ddlDays.DataValueField = "Day";
ddlDays.DataSource = dt;
ddlDays.DataBind();
}
}