Add Item to drop down list

3 posts, 1 answers
  1. Kevin
    Kevin avatar
    265 posts
    Member since:
    Jun 2011

    Posted 23 Jan 2014 Link to this post

    I need to add a default item to all my dropdown lists, but I dont want to have to put it in the database where I load the dropdownlist from.  how can I add a default item at the top of the list for them to Pick an Item from List, itstead of showing first thing from the dtabase.


    How I load the DropDownList then I call the void from within another load statement
     protected void FillDDl()
        {
            sql = "select intPlanId, strFuturePlan from ESGRFuturePlan where bitActive = 1 Order by strFuturePlan";
     
            ddlFuturePlan.DataTextField = "strFuturePlan";
            ddlFuturePlan.DataValueField = "intPlanId";
            ddlFuturePlan.DataSource = c.GetReader(sql);
            ddlFuturePlan.DataBind();
        }
     
    To that list that Loads I need to add an Item such as
    "Pick and Item from List" and give it a value of zero so that I can validate agianst it.

    I then call FillDll() in my Load Person statement.





















  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Jan 2014 Link to this post

    Hi Kevin,

    You can add a Default Item to the RadDropDownList in OnDataBound event. Please have a look into the following C# code which works as expected.

    C#:
    protected void RadDropDownList1_DataBound(object sender, EventArgs e)
    {
        var dropdownlist = (RadDropDownList)sender;
        dropdownlist.Items.Insert(0, new DropDownListItem("DefaultItem"));
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kevin
    Kevin avatar
    265 posts
    Member since:
    Jun 2011

    Posted 24 Jan 2014 Link to this post

    Sweet thanks for the help.
Back to Top