Link to home
Create AccountLog in
Avatar of MSSC_support
MSSC_supportFlag 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">			

Open in new window

I added the entry below to the 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?


Open in new window

Avatar of 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() };
            return View(yrs);


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


Avatar of Lokesh B R
Lokesh B R
Flag of India image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of MSSC_support


Thank you very much. This works as it should.