Creating a drop down list (databounded) and adding a "Please Select"
-
Hi, I'm wondering if this can be done. I have a drop down list that I populate with data from a table. I'd like to add a "Please Select" to the drop down list and make it the first item on the list, so that when the page is loaded, the user will see "Please Select" instead of "amp" in the drop down list. Can this be done? If so how? Thanks. Desmond
-
Hi, I'm wondering if this can be done. I have a drop down list that I populate with data from a table. I'd like to add a "Please Select" to the drop down list and make it the first item on the list, so that when the page is loaded, the user will see "Please Select" instead of "amp" in the drop down list. Can this be done? If so how? Thanks. Desmond
You need to add 'please select' to your data source before binding, as once you bind, you cannot add other items.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Hi, I'm wondering if this can be done. I have a drop down list that I populate with data from a table. I'd like to add a "Please Select" to the drop down list and make it the first item on the list, so that when the page is loaded, the user will see "Please Select" instead of "amp" in the drop down list. Can this be done? If so how? Thanks. Desmond
Hi, Yes its possible. Have a look at this sample. DropDownList1.Items.Add(new ListItem("aaa", "1")); DropDownList1.Items.Add(new ListItem("bbb", "2")); DropDownList1.Items.Insert(0, new ListItem("-- Please Select --")); Items.Add() method adds the items to the Dropdown. Over here you may bind the items from the table, thats fine. Then use the Items.Insert() method specifing the index (here it's 0 which will be the first item in your drop down) and give the ListItem ("Please select" text) as the item to be added. Thx Gayani
-
Hi, Yes its possible. Have a look at this sample. DropDownList1.Items.Add(new ListItem("aaa", "1")); DropDownList1.Items.Add(new ListItem("bbb", "2")); DropDownList1.Items.Insert(0, new ListItem("-- Please Select --")); Items.Add() method adds the items to the Dropdown. Over here you may bind the items from the table, thats fine. Then use the Items.Insert() method specifing the index (here it's 0 which will be the first item in your drop down) and give the ListItem ("Please select" text) as the item to be added. Thx Gayani
Gayani Devapriya wrote:
Over here you may bind the items from the table, thats fine. Then use the Items.Insert() method specifing the index (here it's 0 which will be the first item in your drop down) and give the ListItem ("Please select" text) as the item to be added.
No, if a control is data bound, you cannot add items to it using code.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Hi, I'm wondering if this can be done. I have a drop down list that I populate with data from a table. I'd like to add a "Please Select" to the drop down list and make it the first item on the list, so that when the page is loaded, the user will see "Please Select" instead of "amp" in the drop down list. Can this be done? If so how? Thanks. Desmond
In the properties of the drop down list control, set the AppendDataBoundItems to true. Then, in the Items Collection, add the item "Please Select". Finally, bind the list as you are now. The control will first insert any items that are in the "Items Collection", then it will (as the property states) append the data bound items to the control.
Steve