Search code examples
asp.netcode-behind

Access drop down list from code behind


I have an .aspx file that has 3 drop down lists: ddlMake ddlModel ddlColour

i have a Page_Load function but i cant acces them in the Page_Load function...

using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace NorthwindCascading
{
    public partial class _IndexBasic : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CarService service = new CarService();
                List<string> Makes = service.GetCarMakes();
                ddlMake.DataSource = Makes;
                ddlMake.DataBind();
                ddlMake.Items.Insert(0, " -- Select Make -- ");
            }
        }
    }
}

I have added the code-behind file manually so i guess i am missing something... it just says that the ddlMake element is not defined in current context...any suggestions?


Solution

  • Rather than figure out what went wrong. I suggest you just simply delete the file and re-do what you have done again. Will save your time....