try this, customize it based on your need.
Day:<asp:DropDownList runat="server" ID="ddlD">
</asp:DropDownList>
Month:<asp:DropDownList runat="server" ID="ddlM">
</asp:DropDownList>
Year:<asp:DropDownList runat="server" ID="ddlY">
</asp:DropDownList>
<asp:Label runat="server" ID="lblAge"></asp:Label>
<asp:Button ID="btnCalculate" runat="server" Text="Calculate" OnClick="btnCalculate_Click" />
CS
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 1; i <= 31; i++)
ddlD.Items.Add(i.ToString());
for (int i = 1; i <= 12; i++)
ddlM.Items.Add(i.ToString());
for (int i = 1; i <= 75; i++)
ddlY.Items.Add((DateTime.Now.Year - i).ToString());
}
}
protected void btnCalculate_Click(object sender, EventArgs e)
{
int day,month,year ;
int.TryParse(ddlD.Text, out day);
int.TryParse(ddlM.Text, out month);
int.TryParse(ddlY.Text, out year);
DateTime target = new DateTime(year, month, day);
DateTime now = DateTime.Now;
Age age = new Age(target, now);
lblAge.Text = string.Format(" {0} years, {1} months, and {2} days", age.Years, age.Months, age.Days);
}
used
this[
^]code for calculating the age, just add it in your code