Avatar of MSSC_support
MSSC_support
Flag for United Kingdom of Great Britain and Northern Ireland asked on

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

ASP.NETC#Web Servers

Avatar of undefined
Last Comment
MSSC_support

8/22/2022 - Mon
kblau

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)
ASKER CERTIFIED SOLUTION
Lokesh B R

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MSSC_support

ASKER
Thank you very much. This works as it should.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck