ASP.NET list item not working

I am not a web developer but I have a good understanding of how certain things work but I do not understand this particular problem:

I have a site that has a dropdown list for picking dates. I want to add the dates 2001-2010 onto the code below but cannot seem to get it to function.


 <asp:DropDownList ID="ddlYear" runat="server" Height="21px" Width="56px">			
                        <asp:ListItem>Year</asp:ListItem>
                        <asp:ListItem>2000</asp:ListItem>
                        <asp:ListItem>1999</asp:ListItem>
                        <asp:ListItem>1998</asp:ListItem>
                        <asp:ListItem>1997</asp:ListItem>
                        <asp:ListItem>1996</asp:ListItem>
                        <asp:ListItem>1995</asp:ListItem>
                        <asp:ListItem>1994</asp:ListItem>
                        <asp:ListItem>1993</asp:ListItem>
                        <asp:ListItem>1992</asp:ListItem>
                        <asp:ListItem>1991</asp:ListItem>
                        <asp:ListItem>1990</asp:ListItem>
                        <asp:ListItem>1989</asp:ListItem>
                        <asp:ListItem>1988</asp:ListItem>
                        <asp:ListItem>1987</asp:ListItem>
                        <asp:ListItem>1986</asp:ListItem>
                        <asp:ListItem>1985</asp:ListItem>
                        <asp:ListItem>1984</asp:ListItem>
                        <asp:ListItem>1983</asp:ListItem>
                        <asp:ListItem>1982</asp:ListItem>
                        <asp:ListItem>1981</asp:ListItem>
                        <asp:ListItem>1980</asp:ListItem>
                        <asp:ListItem>1979</asp:ListItem>
                        <asp:ListItem>1978</asp:ListItem>
                        <asp:ListItem>1977</asp:ListItem>
                        <asp:ListItem>1976</asp:ListItem>
                        <asp:ListItem>1975</asp:ListItem>
                        <asp:ListItem>1974</asp:ListItem>
                        <asp:ListItem>1973</asp:ListItem>
                        <asp:ListItem>1972</asp:ListItem>
                        <asp:ListItem>1971</asp:ListItem>

Open in new window




I added the entry below to the asp.net file yet it does not appear. I have the source code and tried to rebuild the whole thing and it still does not show up. Can anyone help me?

 
  <asp:ListItem>2010</asp:ListItem>
                        <asp:ListItem>2009</asp:ListItem>
                        <asp:ListItem>2008</asp:ListItem>
                        <asp:ListItem>2007</asp:ListItem>
                        <asp:ListItem>2006</asp:ListItem>
                        <asp:ListItem>2005</asp:ListItem>
                        <asp:ListItem>2004</asp:ListItem>
                        <asp:ListItem>2003</asp:ListItem>
                        <asp:ListItem>2002</asp:ListItem>
                        <asp:ListItem>2001</asp:ListItem>

Open in new window

MSSC_supportAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kblauCommented:
Do this in MVC
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EEDropdownDates.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            List<SelectListItem> yrs = new List<SelectListItem>();
            for (int i = 1971; i < 2011; i++)
            {
                var newItem = new SelectListItem { Text = i.ToString(), Value = i.ToString() };
                yrs.Add(newItem);
            }
           
            return View(yrs);
        }

    }
}

@model IEnumerable<SelectListItem>
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>


@Html.DropDownList("yrs",Model)
0
Lokesh B RDeveloperCommented:
Hi,

There are 2 ways of doing it.

1. Static Values in ASPX.

<asp:DropDownList ID="ddlYear" runat="server" Height="21px" Width="56px">
            <asp:ListItem>Year</asp:ListItem>
            <asp:ListItem>2010</asp:ListItem>
            <asp:ListItem>2009</asp:ListItem>
            <asp:ListItem>2008</asp:ListItem>
            <asp:ListItem>2007</asp:ListItem>
            <asp:ListItem>2006</asp:ListItem>
            <asp:ListItem>2005</asp:ListItem>
            <asp:ListItem>2004</asp:ListItem>
            <asp:ListItem>2003</asp:ListItem>
            <asp:ListItem>2002</asp:ListItem>
            <asp:ListItem>2001</asp:ListItem>
            <asp:ListItem>2000</asp:ListItem>
            <asp:ListItem>1999</asp:ListItem>
            <asp:ListItem>1998</asp:ListItem>
            <asp:ListItem>1997</asp:ListItem>
            <asp:ListItem>1996</asp:ListItem>
            <asp:ListItem>1995</asp:ListItem>
            <asp:ListItem>1994</asp:ListItem>
            <asp:ListItem>1993</asp:ListItem>
            <asp:ListItem>1992</asp:ListItem>
            <asp:ListItem>1991</asp:ListItem>
            <asp:ListItem>1990</asp:ListItem>
            <asp:ListItem>1989</asp:ListItem>
            <asp:ListItem>1988</asp:ListItem>
            <asp:ListItem>1987</asp:ListItem>
            <asp:ListItem>1986</asp:ListItem>
            <asp:ListItem>1985</asp:ListItem>
            <asp:ListItem>1984</asp:ListItem>
            <asp:ListItem>1983</asp:ListItem>
            <asp:ListItem>1982</asp:ListItem>
            <asp:ListItem>1981</asp:ListItem>
            <asp:ListItem>1980</asp:ListItem>
            <asp:ListItem>1979</asp:ListItem>
            <asp:ListItem>1978</asp:ListItem>
            <asp:ListItem>1977</asp:ListItem>
            <asp:ListItem>1976</asp:ListItem>
            <asp:ListItem>1975</asp:ListItem>
            <asp:ListItem>1974</asp:ListItem>
            <asp:ListItem>1973</asp:ListItem>
            <asp:ListItem>1972</asp:ListItem>
            <asp:ListItem>1971</asp:ListItem>
        </asp:DropDownList>

Open in new window


2. Adding the Values Dynamically.

<asp:DropDownList ID="ddlYear" runat="server" Height="21px" Width="56px">
        </asp:DropDownList>

Open in new window


In Page_Load add the following

 
protected void Page_Load(object sender, EventArgs e)
        {
            List<int> years = new List<int>();
            for (int i = 1971; i <= 2010; i++)
            {
                years.Add(i);
            }

            ddlYear.DataSource = years.OrderByDescending(n => n);
            ddlYear.DataBind();
            ddlYear.Items.Insert(0, new ListItem() { Text = "Year" });
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MSSC_supportAuthor Commented:
Thank you very much. This works as it should.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.