Skip to content

How to insert "--Select--" in combobox

Azamat

Asked Oct 1, 2006, 9:37 PM EDT6 answers
Share
LinkedInX

Hello All,

i am filling country list to Combobox.
This list comes from Database.

now I want to Insert "--Select--" at the top of combox.

i tried cmbcountry.items.insert(0,"--Select--");

but it fired exception that items collections can not be modified after datasource property is set.

Can anyone help me to sort out this problem

Thank in advance

Azamat 


6 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi! Call a function PopulateCountry() to bind the countries list at Page Load event. Here bind the datasource to DropdownList. Then add the code to insert "-- Select--" value at index 0. You can use the code: ListItem FirstItem = new ListItem(); FirstItem.Text = "Select EmailId"; FirstItem.Value = ""; DropDownListCountry.Items.Insert(0,FirstItem); Try this one!
    0
  • 0
    Thanks a lot for your reply.

     But as i wrote in my post it thorws exception Items collection can not be modified after data source property is set

       And also i cant find any object like ListItem, so i didnt use it at all.

    thanks again 



     
    0
  • 0
    try inserting the "--Select--" in the properties of that combo box..i think it's items property(the one with the word "collection" on it's right side,, hehe sorry i don't know what it's called), any way, just type it line-per-line. since you want the "--Select--" to be on the top most, it should be on the first line.hope it helps
    0
  • 0
    use the following query,
    this works for sure.

    "(select convert(nvarchar, '(Select)') as \"field1\") union all (select field1 from table1)"
    0
  • 0
    Hi This this suitable for u afert binding dropdownlist finally add this DropDownList1.Items.Insert(0,(new ListItem("--Select","0"))); Urs, Sarav
    0
  • 0
    Hi This this suitable for u afert binding dropdownlist finally add this DropDownList1.Items.Insert(0,(new ListItem("--Select","0")));
    0