This is a migrated thread and some comments may be shown as answers.

Add Item to drop down list

2 Answers 727 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 23 Jan 2014, 09:05 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 24 Jan 2014, 04:44 AM
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.
0
Kevin
Top achievements
Rank 1
answered on 24 Jan 2014, 01:29 PM
Sweet thanks for the help.
Tags
DropDownList
Asked by
Kevin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Share this question
or