Introduction
Sometimes users face problem for DOB Validation so this article is exactly usefull for validate Date of Birth having three dropdownlist control.
Main
A In this project two xml files named DD.xml and MM.xml are used as a datasources to bind Days(DD) and Months(MM) in dropdwnlist control.Years(YYYY) are also bind in dropdwnlist via code and starts from 1950 To Current Year.But user can also change according to their requirement.Functions are created within class file(DataBL.cs) under BusinessLogic folder.Javascripts functions are also used but they are created on the same page.LeapYear Functionality also provided.Download this project to view more information.
Now let us come to start from SourceView.Drag three dropdownlist controls on the page and Name it as a ddlDay,ddlMonth,ddlYear.
Write following code on Page_Load event to bind Days,Months and Years and other two functions(Bind() and BindYr()) are from DataBL.cs i.e from BusinessLogic.
:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hdnCurrentDate.Value = DateTime.Now.ToString("dd-MM-yyyy")
DataBL.Bind(ref ddlDay,"Day");
DataBL.Bind(ref ddlMonth,"Month");
DataBL.BindYr(ref ddlYear);
}
}
public static void Bind(ref DropDownList ddl, string type)
DataSet ds = new DataSet();if (type == "Day")
ds.ReadXml(HttpContext.Current.Server.MapPath"./DD.xml"));
ds.ReadXml(HttpContext.Current.Server.MapPath("./MM.xml"));
ddl.DataSource = ds;
ddl.DataTextField = "name";
ddl.DataValueField = "value";
ddl.DataBind();
}
public static void BindYr(ref DropDownList ddl)
{
for (int i = 1950; i <= DateTime.Now.Year; i++)
{
ddl.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
}
Conclusion
It is nice to use custom Validation to validate Date of Birth using three dropdownlist controls
References
Include all the useful links or references that can help users learn about your tutorial
- Search Engine
- ASP.NET Resources
Download Source Code
Download Source Code
Download Source Code