calculate age after selecting date from ajax calendar control

Posted by Bhupentiwari under ASP.NET AJAX on 11/29/2012 | Points: 10 | Views : 6308 | Status : [Member] | Replies : 1
Hi
how to calculate age after selecting date from ajax calendar control

here is my code

<tr>
<td align="center" colspan="2">
Employee Form<asp:ScriptManager ID="ScriptManager1"
runat="server">
</asp:ScriptManager>
</td>
</tr>
<tr>
<td>
Name</td>
<td>
<asp:TextBox ID="txtname" autocomplete="off" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Date of Birth</td>
<td style="margin-left: 40px">
<asp:TextBox ID="txtdob" onblur="CalculateAge(this)" runat="server"></asp:TextBox>
<asp:CalendarExtender Animated="true" PopupPosition="Right" PopupButtonID="ImageButton1" TargetControlID="txtdob" ID="CalendarExtender1" runat="server"></asp:CalendarExtender>

<asp:ImageButton Height="18px" Width="22px" ID="ImageButton1" runat="server"
ImageUrl="~/images/calender.jpg" />

</td>

</tr>
<tr>
<td>
Gender</td>
<td>
<asp:DropDownList ID="ddlgender" runat="server">
<asp:ListItem>Please select</asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Job Details</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
Age</td>
<td>

<asp:Label ID="lblage" runat="server"></asp:Label>
</span></td>
</tr>


i want to display age in lblage control.

Thanks n Regards
Bhupendra Tiwari



Responses

Posted by: Sandhyab on: 11/29/2012 [Member] Starter | Points: 25

Up
0
Down
int now = int.Parse(DateTime.Today.ToString("yyyyMMdd"));

int dob = int.Parse(dateDOB.ToString("yyyyMMdd"));
string dif = (now - dob).ToString();
string age = "0";
if (dif.Length > 4)
age = dif.Substring(0, dif.Length - 4);


Thanks & Regards

Bhupentiwari, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response