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

Set Default and add Item

2 Answers 134 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 09 Jul 2008, 08:31 PM
I would like to swap out my asp:DropDownList with your ComboBox but I need to have these two things solved first.

1. How do you set the default item? below is the asp:DropDownList
 DropDownList1.Items.FindByValue("0").Selected = true 

2. How do you add an item to the list and have it at the top when binding other items from a database? below is the asp:DropDownList
 userList.TypeID = (int)Enumeration.ContactType.Consultant;  
 DropDownList1.DataSource = userList.GetUsersByContactType;  
 DropDownList1.DataTextField = "CONTACT_NAME";  
 DropDownList1.DataValueField = "ID";  
 DropDownList1.DataBind();  
 DropDownList1.Items.Add(new ListItem("All", "0")); //This Line

Thanks for the help!

2 Answers, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 10 Jul 2008, 10:38 AM
Hi Mike,

Thank you for contacting us.

You should use this code snippet to set a default value for a RadComboBox:

RadComboBox1.Items.FindItemByValue("0").Selected = true;  
 

To add an item to the combobox at the top, when binding other items, you need to set the AppendDataBoundItems property to true and use the code below:

RadComboBox1.Items.Insert(0, new RadComboBoxItem("All", "0")); 

Please check out the attached file for a reference.

All the best,
Yana
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike
Top achievements
Rank 1
answered on 10 Jul 2008, 12:46 PM
Yana,

Thank You!  You truly are the "Bear"

;)
Tags
ComboBox
Asked by
Mike
Top achievements
Rank 1
Answers by
Yana
Telerik team
Mike
Top achievements
Rank 1
Share this question
or