Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

DropDown list

  Asked By: Trupti    Date: Oct 24    Category: Asp.net    Views: 1018
  

I am populating two drop down list from sql queries. I want to hardcode a choice in the drop down. i.e. "Select One" that would show up as the default selection and the rest of the choices would come from the database query that is populating the drop down box.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Eddie Austin     Answered On: Oct 24

You could do this after the DropDownList is populated with your data:


//if there is one selected set it to false
DropDownList1.SelectedItem.Selected = false;
//create a new ListItem
ListItem li = new ListItem("Select One","Select One");
//let it be selected
li.Selected = true;
//check if there is allready the ListItem that we wish to be in Collection
if (!DropDownList1.Items.Contains(li))
{
//and if not insert it to the first position
DropDownList1.Items.Insert(0,li);
}

 
Answer #2    Answered By: Antonio Dunn     Answered On: Oct 24

I have a dropdown  list in my project. I have added all
months from jan-dec in the dropdown.It displays all
the months but for selecting 'DEC' i have to use
Scrollbar. Can any one tell me how to disable the
scroll bar in the dropdownlist. since the total data
in the dropdown is only 12.

 
Didn't find what you were looking for? Find more on DropDown list Or get search suggestion and latest updates.




Tagged: