I am trying to create dropdown for date of birth.
<select id="ddlDOBDay" />
<select id="ddlDOBMonth" />
<select id="ddlDOBYear" />
I want to add options during page load.Is there a way to achieve that in c#?What would be the best way to do this?Unfortunately I cannot use dropdownlist at this place.
You can use something like this-
<select id="ddlDOBDay" runat="server" />
<select id="ddlDOBMonth" runat="server" />
<select id="ddlDOBYear" runat="server" />
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Add items like below example
ddlDOBDay.Items.Add(new ListItem("1", "1"));
.
.
ddlDOBDay.Items.Add(new ListItem("31", "31"));
ddlDOBMonth.Items.Add(new ListItem("January", "1"));
.
.
ddlDOBDay.Items.Add(new ListItem("December", "12"));
ddlDOBYear.Items.Add(new ListItem("1990", "1990"));
.
.
ddlDOBYear.Items.Add(new ListItem("2015", "2015"));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With