2013-02-03 161 views
0

請參見下圖。我想通過輸入他們的生日信息來自動計算用戶的年齡。有關更多解釋,請參閱下圖。 enter image description here自動年齡計算ASP.Net

這裏是我的register.aspx頁的全碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<%@ Page Language="C#" Debug ="true" %> 
<%@ Import Namespace="System.Data.OleDb" %> 
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> 

<head runat="server"> 
<script type="text/c#" runat="server"> 


    protected void AccessDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e) 
    { 
     string query = "SELECT @@IDENTITY"; 
     OleDbCommand cmd = new OleDbCommand(query, (OleDbConnection)e.Command.Connection); 
     int newid = (int)cmd.ExecuteScalar(); 
     Response.Redirect("registerpage2.aspx?id=" + newid); 
    } 
</script> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Register</title> 
<style type="text/css"> 
.style1 { 
    background-image: url('images/REGISTER.jpg'); 
} 
#form2 { 
    height: 75px; 
    padding: 0px; 
    margin: 0px; 
    table-layout: auto; 
    border-collapse: collapse; 
    border-spacing: 0px; 
} 
.style2 { 
    border-width: 0px; 
} 
.style4 { 
    text-align: right; 
} 
.style5 { 
    margin-bottom: 0px; 
} 
.style6 { 
    text-align: center; 
} 
</style> 
<script type="text/javascript"> 
<!-- 
function FP_swapImgRestore() {//v1.0 
var doc=document,i; if(doc.$imgSwaps) { for(i=0;i<doc.$imgSwaps.length;i++) { 
    var elm=doc.$imgSwaps[i]; if(elm) { elm.src=elm.$src; elm.$src=null; } } 
    doc.$imgSwaps=null; } 
} 

function FP_swapImg() {//v1.0 
var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length; 
n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm; 
elm.$src=elm.src; elm.src=args[n+1]; } } 
} 

function FP_preloadImgs() {//v1.0 
var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array(); 
for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; } 
} 

function FP_getObjectByID(id,o) {//v1.0 
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id); 
else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el; 
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c) 
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; } 
f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements; 
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } } 
return null; 
} 
// --> 
</script> 
</head> 

<body onload="FP_preloadImgs(/*url*/'images/hover home.jpg',/*url*/'images/hover LCUP.jpg',/*url*/'images/hover help.jpg')" style="margin: 0; background-color: #808080"> 

<form id="InputForm" runat="server" class="style5" style="height: 646px"> 

<table style="width: 941px; height: 646px" cellspacing="0" cellpadding="0" align="center" class="style1"> 
    <!-- MSTableType="layout" --> 
    <tr> 
     <td valign="top"> 
     <a href="default.htm"> 
     <img alt="" src="images/normal%20home.jpg" width="72" height="54" id="img1" onmouseout="FP_swapImgRestore()" onmouseover="FP_swapImg(1,1,/*id*/'img1',/*url*/'images/hover home.jpg')" class="style2" /></a></td> 
     <td valign="top"> 
     &nbsp;</td> 
     <td valign="top"> 
     &nbsp;</td> 
     <td>&nbsp;</td> 
     <td valign="top"> 
     <a href="http://www.lcup.edu.ph"> 
     <img alt="" src="images/normal%20lcup.jpg" width="47" height="54" id="img4" onmouseout="FP_swapImgRestore()" onmouseover="FP_swapImg(1,1,/*id*/'img4',/*url*/'images/hover LCUP.jpg')" /></a></td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td valign="top" colspan="2" style="height: 58px; "> 
     <img alt="" src="images/normal%20help.jpg" width="77" height="54" id="img5" onmouseout="FP_swapImgRestore()" onmouseover="FP_swapImg(1,1,/*id*/'img5',/*url*/'images/hover help.jpg')" /></td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td valign="top">&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td style="height: 95px">&nbsp;</td> 
     </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td valign="top"> 
    <asp:AccessDataSource runat="server" ID="AccessDataSource1" DeleteCommand="DELETE FROM [PendingRecords] WHERE [ID] = ?" InsertCommand="INSERT INTO [PendingRecords] ([Username], [Password], [FirstName], [LastName], [MiddleName], [Address], [Age], [Gender], [ContactNumber], [PlateNumber], [Color], [Brand], [LiscensedNumber], [SSSNumber], [TIN], [Type], [Model], [BirthDay], [BirthMonth], [BirthYear]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" UpdateCommand="UPDATE [PendingRecords] SET [Username] = ?, [Password] = ?, [FirstName] = ?, [LastName] = ?, [MiddleName] = ?, [Address] = ?, [Age] = ?, [Gender] = ?, [ContactNumber] = ?, [PlateNumber] = ?, [Color] = ?, [Brand] = ?, [LiscensedNumber] = ?, [SSSNumber] = ?, [TIN] = ?, [Type] = ?, [Model] = ?, [BirthDay] = ?, [BirthMonth] = ?, [BirthYear] = ? WHERE [ID] = ?" DataFile="_private/records.mdb" SelectCommand="SELECT * FROM [PendingRecords]" OnInserted="AccessDataSource1_Inserted"> 
     <DeleteParameters> 
      <asp:parameter Name="ID" Type="Int32" /> 
     </DeleteParameters> 
     <UpdateParameters> 
      <asp:parameter Name="Username" Type="String" /> 
      <asp:parameter Name="Password" Type="String" /> 
      <asp:parameter Name="FirstName" Type="String" /> 
      <asp:parameter Name="LastName" Type="String" /> 
      <asp:parameter Name="MiddleName" Type="String" /> 
      <asp:parameter Name="Address" Type="String" /> 
      <asp:parameter Name="Age" Type="String" /> 
      <asp:parameter Name="Gender" Type="String" /> 
      <asp:parameter Name="ContactNumber" Type="String" /> 
      <asp:parameter Name="PlateNumber" Type="String" /> 
      <asp:parameter Name="Color" Type="String" /> 
      <asp:parameter Name="Brand" Type="String" /> 
      <asp:parameter Name="LiscensedNumber" Type="String" /> 
      <asp:parameter Name="SSSNumber" Type="String" /> 
      <asp:parameter Name="TIN" Type="String" /> 
      <asp:parameter Name="Type" Type="String" /> 
      <asp:parameter Name="Model" Type="String" /> 
      <asp:parameter Name="BirthDay" Type="String" /> 
      <asp:parameter Name="BirthMonth" Type="String" /> 
      <asp:parameter Name="BirthYear" Type="String" /> 
      <asp:parameter Name="ID" Type="Int32" /> 
     </UpdateParameters> 
     <InsertParameters> 
      <asp:parameter Name="Username" Type="String" /> 
      <asp:parameter Name="Password" Type="String" /> 
      <asp:parameter Name="FirstName" Type="String" /> 
      <asp:parameter Name="LastName" Type="String" /> 
      <asp:parameter Name="MiddleName" Type="String" /> 
      <asp:parameter Name="Address" Type="String" /> 
      <asp:parameter Name="Age" Type="String" /> 
      <asp:parameter Name="Gender" Type="String" /> 
      <asp:parameter Name="ContactNumber" Type="String" /> 
      <asp:parameter Name="PlateNumber" Type="String" /> 
      <asp:parameter Name="Color" Type="String" /> 
      <asp:parameter Name="Brand" Type="String" /> 
      <asp:parameter Name="LiscensedNumber" Type="String" /> 
      <asp:parameter Name="SSSNumber" Type="String" /> 
      <asp:parameter Name="TIN" Type="String" /> 
      <asp:parameter Name="Type" Type="String" /> 
      <asp:parameter Name="Model" Type="String" /> 
      <asp:parameter Name="BirthDay" Type="String" /> 
      <asp:parameter Name="BirthMonth" Type="String" /> 
      <asp:parameter Name="BirthYear" Type="String" /> 
     </InsertParameters> 
    </asp:AccessDataSource> 
     </td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td style="height: 33px;">&nbsp;</td> 
     </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td style="height: 76px">&nbsp;</td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td valign="top" colspan="8"> 
    <asp:FormView runat="server" id="InputForm1" DataSourceID="AccessDataSource1" DataKeyNames="ID" DefaultMode="Insert" Width="832px"> 
     <EditItemTemplate> 
      ID: 
      <asp:Label Text='<%# Eval("ID") %>' runat="server" id="IDLabel1" /> 
      <br /> 
      Username: 
      <asp:TextBox Text='<%# Bind("Username") %>' runat="server" id="UsernameTextBox" /> 
      <br /> 
      Password: 
      <asp:TextBox Text='<%# Bind("Password") %>' runat="server" id="PasswordTextBox" /> 
      <br /> 
      FirstName: 
      <asp:TextBox Text='<%# Bind("FirstName") %>' runat="server" id="FirstNameTextBox" /> 
      <br /> 
      LastName: 
      <asp:TextBox Text='<%# Bind("LastName") %>' runat="server" id="LastNameTextBox" /> 
      <br /> 
      MiddleName: 
      <asp:TextBox Text='<%# Bind("MiddleName") %>' runat="server" id="MiddleNameTextBox" /> 
      <br /> 
      Address: 
      <asp:TextBox Text='<%# Bind("Address") %>' runat="server" id="AddressTextBox" /> 
      <br /> 
      Birhtday: 
      <asp:TextBox Text='<%# Bind("Birhtday") %>' runat="server" id="BirhtdayTextBox" /> 
      <br /> 
      ContactNumber: 
      <asp:TextBox Text='<%# Bind("ContactNumber") %>' runat="server" id="ContactNumberTextBox" /> 
      <br /> 
      PlateNumber: 
      <asp:TextBox Text='<%# Bind("PlateNumber") %>' runat="server" id="PlateNumberTextBox" /> 
      <br /> 
      Color: 
      <asp:TextBox Text='<%# Bind("Color") %>' runat="server" id="ColorTextBox" /> 
      <br /> 
      Brand: 
      <asp:TextBox Text='<%# Bind("Brand") %>' runat="server" id="BrandTextBox" /> 
      <br /> 
      LiscensedNumber: 
      <asp:TextBox Text='<%# Bind("LiscensedNumber") %>' runat="server" id="LiscensedNumberTextBox" /> 
      <br /> 
      <asp:LinkButton runat="server" Text="Update" CommandName="Update" id="UpdateButton" CausesValidation="True" /> 
      &nbsp; 
      <asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" id="UpdateCancelButton" CausesValidation="False" /> 
     </EditItemTemplate> 
     <InsertItemTemplate> 
      <div class="style6"> 
       <table style="width: 100%; text-align: right" align="right" cellspacing="0" cellpadding="0" id="form2" class="style2"> 
        <tr> 
         <td style="text-align: right; height: 25px; width: 111px;"> 
         Firstname:</td> 
         <td style="width: 280px; height: 25px;"> 
         <div> 
          <asp:TextBox Text='<%# Bind("FirstName") %>' runat="server" id="FName" Width="267px" Height="10px" ValidationGroup="reg"> 
          </asp:TextBox> 
         </div> 
         </td> 
         <td style="height: 25px; text-align: left; width: 3px;"> 
         </td> 
         <td style="height: 25px; text-align: left;"> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="!" id="RequiredFieldValidator1" style="text-align: left" ControlToValidate="FName" ValidationGroup="reg" ForeColor="#FF9933"> 
         </asp:RequiredFieldValidator> 
         </td> 
         <td style="height: 25px; text-align: left;">&nbsp;</td> 
        </tr> 
        <tr> 
         <td style="width: 111px; height: 25px;">Lastname:</td> 
         <td style="width: 280px; height: 25px;"> 
         <asp:TextBox runat="server" id="TextBox6" Width="267px" Height="10px" Text='<%# Bind("LastName") %>' ValidationGroup="reg"> 
         </asp:TextBox> 
         </td> 
         <td style="height: 25px; text-align: left; width: 3px;"> 
         &nbsp;</td> 
         <td style="height: 25px; text-align: left;"> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="!" id="RequiredFieldValidator2" ControlToValidate="TextBox6" ValidationGroup="reg" ForeColor="#FF9933"> 
         </asp:RequiredFieldValidator> 
         </td> 
         <td style="height: 25px; text-align: left;">&nbsp;</td> 
        </tr> 
        <tr> 
         <td style="width: 111px; height: 25px;">Middle Name:</td> 
         <td style="width: 280px; height: 25px;"> 
         <asp:TextBox runat="server" id="TextBox7" Width="267px" Height="10px" Text='<%# Bind("MiddleName") %>' ValidationGroup="reg"> 
         </asp:TextBox> 
         </td> 
         <td style="height: 25px; text-align: left; width: 3px;"> 
         &nbsp;</td> 
         <td style="height: 25px; text-align: left;"> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="!" id="RequiredFieldValidator3" ControlToValidate="TextBox7" ValidationGroup="reg" ForeColor="#FF9933"> 
         </asp:RequiredFieldValidator> 
         </td> 
         <td style="height: 25px; text-align: left;">&nbsp;</td> 
        </tr> 
        <tr> 
         <td style="width: 111px; height: 25px;">Address:</td> 
         <td style="width: 280px; height: 25px;"> 
         <asp:TextBox runat="server" id="TextBox8" Width="267px" Height="10px" Text='<%# Bind("Address") %>' ValidationGroup="reg"> 
         </asp:TextBox> 
         </td> 
         <td style="height: 25px; text-align: left; width: 3px;"> 
         &nbsp;</td> 
         <td style="height: 25px; text-align: left;"> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="!" id="RequiredFieldValidator4" style="text-align: left" ControlToValidate="TextBox8" ValidationGroup="reg" ForeColor="#FF9933"> 
         </asp:RequiredFieldValidator> 
         </td> 
         <td style="height: 25px; text-align: left;">&nbsp;</td> 
        </tr> 
        <tr> 
         <td style="width: 111px; height: 25px;">Contact No.:</td> 
         <td style="width: 280px; height: 25px;"> 
         <asp:TextBox runat="server" id="TextBox9" Width="267px" Height="10px" Text='<%# Bind("ContactNumber") %>' ValidationGroup="reg"> 
         </asp:TextBox> 
         </td> 
         <td style="height: 25px; text-align: left; width: 3px;"> 
         &nbsp;</td> 
         <td style="height: 25px; text-align: left;"> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="!" id="RequiredFieldValidator5" ControlToValidate="TextBox9" ValidationGroup="reg" Display="Dynamic" ForeColor="#FF9933"> 
         </asp:RequiredFieldValidator> 
         <asp:RegularExpressionValidator runat="server" ErrorMessage="! 09######### - Must be 11 digits." id="RegularExpressionValidator1" ControlToValidate="TextBox9" ValidationExpression="^\d{11}$" ValidationGroup="reg" Display="Dynamic" ForeColor="#FF9933"> 
         </asp:RegularExpressionValidator> 
         </td> 
         <td style="height: 25px; text-align: left;">&nbsp;</td> 
        </tr> 
        <tr> 
         <td style="width: 111px">Gender:</td> 
         <td style="width: 280px" class="style4"> 
         <asp:RadioButtonList runat="server" id="RadioButtonList1" Width="200px" ValidationGroup="reg" RepeatDirection="Horizontal" RepeatColumns="2" RepeatLayout="Flow" Height="20px" SelectedValue='<%# Bind("Gender") %>'> 
          <asp:ListItem>Male</asp:ListItem> 
          <asp:ListItem>Female</asp:ListItem> 
         </asp:RadioButtonList> 
         </td> 
         <td style="text-align: left; width: 3px;">&nbsp;</td> 
         <td style="text-align: left"> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="!" id="RequiredFieldValidator12" ValidationGroup="reg" ControlToValidate="RadioButtonList1" ForeColor="#FF9933"> 
         </asp:RequiredFieldValidator> 
         </td> 
         <td style="text-align: left">&nbsp;</td> 
        </tr> 
        <tr> 
         <td style="width: 111px">Birthday:</td> 
         <td style="width: 280px" class="style4"> 
         <asp:DropDownList runat="server" id="DropDownList2" SelectedValue='<%# Bind("BirthMonth") %>'> 
          <asp:ListItem>Month</asp:ListItem> 
          <asp:ListItem>January</asp:ListItem> 
          <asp:ListItem>February</asp:ListItem> 
          <asp:ListItem>March</asp:ListItem> 
          <asp:ListItem>April</asp:ListItem> 
          <asp:ListItem>May</asp:ListItem> 
          <asp:ListItem>June</asp:ListItem> 
          <asp:ListItem>July</asp:ListItem> 
          <asp:ListItem>August</asp:ListItem> 
          <asp:ListItem>September</asp:ListItem> 
          <asp:ListItem>October</asp:ListItem> 
          <asp:ListItem>November</asp:ListItem> 
          <asp:ListItem>December</asp:ListItem> 
         </asp:DropDownList> 
         <asp:DropDownList runat="server" id="DropDownList3" SelectedValue='<%# Bind("BirthDay") %>'> 
          <asp:ListItem>Day</asp:ListItem> 
          <asp:ListItem>1</asp:ListItem> 
          <asp:ListItem>2</asp:ListItem> 
          <asp:ListItem>3</asp:ListItem> 
          <asp:ListItem>4</asp:ListItem> 
          <asp:ListItem>5</asp:ListItem> 
          <asp:ListItem>6</asp:ListItem> 
          <asp:ListItem>7</asp:ListItem> 
          <asp:ListItem>8</asp:ListItem> 
          <asp:ListItem>9</asp:ListItem> 
          <asp:ListItem>10</asp:ListItem> 
          <asp:ListItem>11</asp:ListItem> 
          <asp:ListItem>12</asp:ListItem> 
          <asp:ListItem>13</asp:ListItem> 
          <asp:ListItem>14</asp:ListItem> 
          <asp:ListItem>15</asp:ListItem> 
          <asp:ListItem>16</asp:ListItem> 
          <asp:ListItem>17</asp:ListItem> 
          <asp:ListItem>18</asp:ListItem> 
          <asp:ListItem>19</asp:ListItem> 
          <asp:ListItem>20</asp:ListItem> 
          <asp:ListItem>21</asp:ListItem> 
          <asp:ListItem>22</asp:ListItem> 
          <asp:ListItem>23</asp:ListItem> 
          <asp:ListItem>24</asp:ListItem> 
          <asp:ListItem>25</asp:ListItem> 
          <asp:ListItem>26</asp:ListItem> 
          <asp:ListItem>27</asp:ListItem> 
          <asp:ListItem>28</asp:ListItem> 
          <asp:ListItem>29</asp:ListItem> 
          <asp:ListItem>30</asp:ListItem> 
          <asp:ListItem>31</asp:ListItem> 
         </asp:DropDownList> 
         <asp:DropDownList runat="server" id="DropDownList4" SelectedValue='<%# Bind("BirthYear") %>'> 
          <asp:ListItem>Year</asp:ListItem> 
          <asp:ListItem>1920</asp:ListItem> 
          <asp:ListItem>1921</asp:ListItem> 
          <asp:ListItem>1922</asp:ListItem> 
          <asp:ListItem>1923</asp:ListItem> 
          <asp:ListItem>1924</asp:ListItem> 
          <asp:ListItem>1925</asp:ListItem> 
          <asp:ListItem>1926</asp:ListItem> 
          <asp:ListItem>1927</asp:ListItem> 
          <asp:ListItem>1928</asp:ListItem> 
          <asp:ListItem>1929</asp:ListItem> 
          <asp:ListItem>1930</asp:ListItem> 
          <asp:ListItem>1931</asp:ListItem> 
          <asp:ListItem>1932</asp:ListItem> 
          <asp:ListItem>1933</asp:ListItem> 
          <asp:ListItem>1933</asp:ListItem> 
          <asp:ListItem>1934</asp:ListItem> 
          <asp:ListItem>1935</asp:ListItem> 
          <asp:ListItem>1936</asp:ListItem> 
          <asp:ListItem>1937</asp:ListItem> 
          <asp:ListItem>1938</asp:ListItem> 
          <asp:ListItem>1939</asp:ListItem> 
          <asp:ListItem>1940</asp:ListItem> 
          <asp:ListItem>1941</asp:ListItem> 
          <asp:ListItem>1942</asp:ListItem> 
          <asp:ListItem>1943</asp:ListItem> 
          <asp:ListItem>1944</asp:ListItem> 
          <asp:ListItem>1945</asp:ListItem> 
          <asp:ListItem>1946</asp:ListItem> 
          <asp:ListItem>1947</asp:ListItem> 
          <asp:ListItem Value="1948">1948</asp:ListItem> 
          <asp:ListItem>1949</asp:ListItem> 
          <asp:ListItem>1950</asp:ListItem> 
          <asp:ListItem>1951</asp:ListItem> 
          <asp:ListItem>1952</asp:ListItem> 
          <asp:ListItem>1953</asp:ListItem> 
          <asp:ListItem>1954</asp:ListItem> 
          <asp:ListItem>1955</asp:ListItem> 
          <asp:ListItem>1956</asp:ListItem> 
          <asp:ListItem>1957</asp:ListItem> 
          <asp:ListItem>1958</asp:ListItem> 
          <asp:ListItem>1959</asp:ListItem> 
          <asp:ListItem>1960</asp:ListItem> 
          <asp:ListItem>1961</asp:ListItem> 
          <asp:ListItem>1962</asp:ListItem> 
          <asp:ListItem>1963</asp:ListItem> 
          <asp:ListItem>1964</asp:ListItem> 
          <asp:ListItem>1965</asp:ListItem> 
          <asp:ListItem>1966</asp:ListItem> 
          <asp:ListItem>1967</asp:ListItem> 
          <asp:ListItem>1968</asp:ListItem> 
          <asp:ListItem>1969</asp:ListItem> 
          <asp:ListItem>1970</asp:ListItem> 
          <asp:ListItem>1971</asp:ListItem> 
          <asp:ListItem>1972</asp:ListItem> 
          <asp:ListItem>1973</asp:ListItem> 
          <asp:ListItem>1974</asp:ListItem> 
          <asp:ListItem>1975</asp:ListItem> 
          <asp:ListItem>1976</asp:ListItem> 
          <asp:ListItem>1977</asp:ListItem> 
          <asp:ListItem>1978</asp:ListItem> 
          <asp:ListItem>1979</asp:ListItem> 
          <asp:ListItem>1980</asp:ListItem> 
          <asp:ListItem>1981</asp:ListItem> 
          <asp:ListItem>1982</asp:ListItem> 
          <asp:ListItem>1983</asp:ListItem> 
          <asp:ListItem>1984</asp:ListItem> 
          <asp:ListItem>1985</asp:ListItem> 
          <asp:ListItem>1986</asp:ListItem> 
          <asp:ListItem>1987</asp:ListItem> 
          <asp:ListItem>1988</asp:ListItem> 
          <asp:ListItem>1989</asp:ListItem> 
          <asp:ListItem>1990</asp:ListItem> 
          <asp:ListItem>1991</asp:ListItem> 
          <asp:ListItem>1992</asp:ListItem> 
          <asp:ListItem>1993</asp:ListItem> 
          <asp:ListItem>1994</asp:ListItem> 
          <asp:ListItem>1995</asp:ListItem> 
          <asp:ListItem>1996</asp:ListItem> 
          <asp:ListItem>1997</asp:ListItem> 
          <asp:ListItem>1998</asp:ListItem> 
          <asp:ListItem>1999</asp:ListItem> 
          <asp:ListItem>2000</asp:ListItem> 
          <asp:ListItem>2001</asp:ListItem> 
          <asp:ListItem>2002</asp:ListItem> 
          <asp:ListItem>2003</asp:ListItem> 
          <asp:ListItem>2004</asp:ListItem> 
          <asp:ListItem>2005</asp:ListItem> 
          <asp:ListItem>2006</asp:ListItem> 
          <asp:ListItem>2007</asp:ListItem> 
          <asp:ListItem>2008</asp:ListItem> 
          <asp:ListItem>2009</asp:ListItem> 
          <asp:ListItem>2010</asp:ListItem> 
          <asp:ListItem>2011</asp:ListItem> 
          <asp:ListItem>2012</asp:ListItem> 
          <asp:ListItem>2013</asp:ListItem> 
         </asp:DropDownList> 
         </td> 
         <td style="text-align: left; width: 3px;">&nbsp;</td> 
         <td style="text-align: left"> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="! Month" id="RequiredFieldValidator13" ControlToValidate="DropDownList2" ValidationGroup="reg" Display="Dynamic" InitialValue="Month" ForeColor="#FF9933"> 
         </asp:RequiredFieldValidator> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="! Day" id="RequiredFieldValidator14" ValidationGroup="reg" ControlToValidate="DropDownList3" Display="Dynamic" InitialValue="Day" ForeColor="#FF9933"> 
         </asp:RequiredFieldValidator> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="! Year" id="RequiredFieldValidator15" Display="Dynamic" ControlToValidate="DropDownList4" ValidationGroup="reg" InitialValue="Year" ForeColor="#FF9933"> 
         </asp:RequiredFieldValidator> 
         </td> 
         <td style="text-align: left">&nbsp;</td> 
        </tr> 
        <tr> 
         <td style="width: 111px">Age:</td> 
         <td style="width: 280px" class="style4"> 
         <asp:TextBox runat="server" id="TextBox1" Text='<%# Bind("Age") %>' Height="10px" Width="70px"> 
         </asp:TextBox> 
         </td> 
         <td style="text-align: left; width: 3px;">&nbsp;</td> 
         <td style="text-align: left; vertical-align: middle; "> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="! Please specify your age." id="RequiredFieldValidator16" ControlToValidate="TextBox1" ValidationGroup="reg" Display="Dynamic" ForeColor="#FF9933"> 
         </asp:RequiredFieldValidator> 
         <asp:RegularExpressionValidator runat="server" ErrorMessage="! Invalid Age" id="RegularExpressionValidator2" ControlToValidate="TextBox1" ValidationExpression="\d{2}" Display="Dynamic" ValidationGroup="reg" ForeColor="#FF9933"> 
         </asp:RegularExpressionValidator> 
         </td> 
         <td style="text-align: left; vertical-align: middle; "> 
         <asp:ImageButton CommandName="Insert" runat="server" id="Submit" alt="" src="images/normalnext.jpg" width="146px" height="43px" style="float: right" ValidationGroup="reg" /> 
         </td> 
        </tr> 
       </table> 
       <br /> 
       <br /> 
       <br /> 
       <br /> 
       <br /> 
       <br /> 
       <br /> 
       <br /> 
       <br /> 
       <br /> 
      </div> 
      <br /> 
     </InsertItemTemplate> 
     <ItemTemplate> 
      <table style="width: 100%; text-align: right" align="right" cellspacing="0" cellpadding="0" id="form3" class="style2"> 
       <tr> 
        <td style="text-align: right; height: 25px;">Firstname:</td> 
        <td style="width: 280px; height: 25px;"> 
        <div> 
         <asp:Label Text='<%# Bind("FirstName") %>' runat="server" id="FirstNameLabel" /> 
        </div> 
        </td> 
        <td style="height: 25px">&nbsp;</td> 
       </tr> 
       <tr> 
        <td style="width: 108px; height: 25px;">Lastname:</td> 
        <td style="width: 280px; height: 25px;"> 
        <asp:Label Text='<%# Bind("LastName") %>' runat="server" id="LastNameLabel" /> 
        </td> 
        <td style="height: 25px"></td> 
       </tr> 
       <tr> 
        <td style="width: 108px; height: 25px;">Middle Name:</td> 
        <td style="width: 280px; height: 25px;"> 
        <asp:Label Text='<%# Bind("MiddleName") %>' runat="server" id="MiddleNameLabel" /> 
        </td> 
        <td style="height: 25px"></td> 
       </tr> 
       <tr> 
        <td style="width: 108px; height: 25px;">Address:</td> 
        <td style="width: 280px; height: 25px;"> 
        <asp:Label Text='<%# Bind("Address") %>' runat="server" id="AddressLabel" /> 
        </td> 
        <td style="height: 25px"></td> 
       </tr> 
       <tr> 
        <td style="width: 108px; height: 25px;">Contact No.:</td> 
        <td style="width: 280px; height: 25px;"> 
        <asp:Label Text='<%# Bind("ContactNumber") %>' runat="server" id="ContactNumberLabel" /> 
        </td> 
        <td style="height: 25px"></td> 
       </tr> 
       <tr> 
        <td style="width: 108px">Gender:</td> 
        <td style="width: 280px"><asp:RadioButton runat="server" id="Female0" Text="Female" /><asp:RadioButton runat="server" id="Male0" Text="Male" /> 
        </td> 
        <td>&nbsp;</td> 
       </tr> 
       <tr> 
        <td style="width: 108px">Birthday</td> 
        <td style="width: 280px"><asp:DropDownList runat="server" id="DropDownList2" SelectedValue='<%# Bind("BirthMonth") %>'/><asp:DropDownList runat="server" id="DropDownList3" SelectedValue='<%# Bind("BirthDay") %>'/> <asp:DropDownList runat="server" id="DropDownList4" SelectedValue='<%# Bind("BirthYear") %>'/>   </td> 
        <td>&nbsp;</td> 
       </tr> 


      </table> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      &nbsp; 
      <asp:LinkButton runat="server" Text="Edit" CommandName="Edit" id="EditButton" CausesValidation="False" /> 
      &nbsp; 
      <asp:LinkButton runat="server" Text="Delete" CommandName="Delete" id="DeleteButton" CausesValidation="False" /> 
      &nbsp; 
      <asp:LinkButton runat="server" Text="New" CommandName="New" id="NewButton" CausesValidation="False" /> 
     </ItemTemplate> 
    </asp:FormView> 
     </td> 
     <td style="height: 296px">&nbsp;</td> 
    </tr> 
    <tr> 
     <td style="width: 72px">&nbsp;</td> 
     <td style="width: 72px">&nbsp;</td> 
     <td style="width: 72px">&nbsp;</td> 
     <td style="width: 230px">&nbsp;</td> 
     <td style="width: 51px">&nbsp;</td> 
     <td style="width: 29px">&nbsp;</td> 
     <td style="width: 300px">&nbsp;</td> 
     <td style="width: 37px">&nbsp;</td> 
     <td style="width: 60px">&nbsp;</td> 
     <td style="height: 88px; width: 18px">&nbsp;</td> 
    </tr> 
</table> 

</form> 

     </body> 

</html> 
+1

可能重複:** [我如何計算一個人的年齡(http://stackoverflow.com/a/1404/500725)** –

+0

@SivaCharan你能編輯我的代碼嗎?那麼我可以複製然後嘗試運行?請 –

回答

1

試試這個代碼,我在谷歌發現,它應該做的伎倆:

DateTime now = DateTime.Now; 
int age = now.Year - bday.Year; 

if (now < bday.AddYears(age)) 
    age--; 
+0

我要把這個代碼放在哪裏?我在我的註冊頁面使用FormView控件 –

+0

噢,對不起,我不知道FormView控件不使用後面的代碼。裏面的<腳本類型=「文本/ C#」 RUNAT =「服務器」>腳本,你可以創建任何你喜歡的一個功能,並將其命名爲像GetAge()或。 – PmanAce

1

使用JavaScript

function getAge(dateString) { //parameter date from form, should look like "03/21/1986" 
    var today = new Date(); 
    var birthDate = new Date(dateString); 
    var age = today.getFullYear() - birthDate.getFullYear(); 
    var m = today.getMonth() - birthDate.getMonth(); 
    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { 
     age--; 
    } 
    return age; 
} 
+0

編譯器錯誤信息:CS1001:標識符預期......在這條線的功能getAge(dateString){//從形式 –

+0

參數日期不可能的,請 – 2013-02-03 07:34:15

+0

請查看以上我的代碼?因爲我只是使用dropdownlist手動製作生日表單。 –