📜  如何在 C# 代码示例中使用组合框查找年龄

📅  最后修改于: 2022-03-11 14:48:49.546000             🧑  作者: Mango

代码示例1
protected void btn_Click(object sender, EventArgs e)
    {
         // here you use your ddl,combobox or etc where age date is inserted
        DateTime dtStart = DateTime.Parse(txtDoB.Text);
        TimeSpan sp = DateTime.Now - dtStart;
        int year = "18";
        int days = 365;
        int total = year * days;

        if (sp.Days < total)
        {

            txtDoB.Text = "Not Valid";
            lblMess.Text = "You can not be under 18 years";
            lblMess.CssClass = "Errr";
            return;
        }
}