2

I Have list "Department" and takes the data from it. I want the first value in DropDownMenu to be "Not a dept"...


enter image description here


protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            using (SPSite site = new SPSite("http://sf-spsdev04/sites/sitecolection/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["Departments"];
                    dropDep.DataSource = list.Items;
                    dropDep.DataValueField = "Title";
                    dropDep.DataTextField = "Title";
                    dropDep.DataBind();
                }
            }
        }
    }

1 Answer 1

3

Add below line of code under dropDep.DataBind();

ListItem newItem = new ListItem("Not a dept", "0");
dropDep.Items.Insert(0, newItem);
1
  • Please help me for this question ... ----> link
    – Goshky
    Mar 16, 2016 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.