Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add "Select" item in DropDown

I am using ASP.NET dynamic data. In Insert.aspx page, I have a couple of dropdowns to be selected. The fields represented by Dropdown are Required fields in database. So dropdown does not show 'Select' as default option in dropdown. I want to add 'Select' option at top of other records from database shown in dropdown. Note that field is not Required field, hence 'Select' option is not being show over there by dynamic data by default. How can I accomplish this?

like image 810
Manoj Attal Avatar asked Sep 01 '26 05:09

Manoj Attal


1 Answers

Add your "select" item after binding your dropdownlists by using Insert method :

myDropDownList.DataBind();
// To make it the first element at the list, use 0 index : 
myDropDownList.Items.Insert(0, new ListItem("Select", string.Empty));
like image 103
Canavar Avatar answered Sep 05 '26 18:09

Canavar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!