I had created a dropdownlist box as follows. The contents of default.aspx is listed below
<asp:DropDownList runat="server" ID="day" CssClass="dobselect">
<asp:ListItem Value="0" Text="DAY"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList runat="server" ID="month" CssClass="dobselect">
<asp:ListItem Value="0" Text="MONTH"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="year" CssClass="dobselect" runat="server">
<asp:ListItem Value="0" Text="YEAR"></asp:ListItem>
</asp:DropDownList>
Then in the default.cs.aspx I had added the following code to display the dropdownlist boxe's values
private void autofilldate(int incrementBy, int max, int itemcount)//to automatically generate days in a dropdownlist
{
int incr = incrementBy;
for (int i = 0; i <itemcount; i++)
{
if (incrementBy <= max)
{
day.Items.Add(new ListItem(incrementBy.ToString(), incrementBy.ToString()));
}
}
}//end of autofilldl
// ....more code for displaying month and year
private void autofillyr(int incrementBy, int maxyr, int no_year)
{
int yr = incrementBy;
for (int i =0; i < no_year; i++)
{
if (incrementBy <= maxyr)
{
year.Items.Add(new ListItem(incrementBy.ToString(), incrementBy.ToString()));
incrementBy =incrementBy + yr;
}
protected void Page_Load(object sender, EventArgs e)
{
autofilldate(1, 31, 31);
autofillmonth(1, 12, 12);
autofillyr(1, 2050, 2076);
}
when it is executed both the day and month is working fine, but for the year it is displaying as 1 2 3..... 2050 and so on. what I need is it must start from the year"1900" it should not get displayed from the value 1 to 2050. How can I do this? anyone please help me.