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

Inserting new item into RadCombobox

2 Answers 112 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Amit
Top achievements
Rank 1
Amit asked on 18 Oct 2010, 11:02 AM
Hey everyone,

I am using a RadCombBox on my page that i've binded to a database column.Now,i want it to show an initial value at page_load like select your Name.i am doing this--
if (!IsPostBack) 
{
    RadComboBox1.Items.Insert(0, new RadComboBoxItem("Select Your Name", "0"));
     RadComboBox1.SelectedIndex = 0;
}
not workin,am i missing something?..plz help

Thanks
Amit

2 Answers, 1 is accepted

Sort by
0
Accepted
Cori
Top achievements
Rank 2
answered on 18 Oct 2010, 12:59 PM
Hello Amit,

If you are binding the combobox after this line or using a DataSource control, you should set AppendDataBoundItems="true", to prevent the binding from clearing the items collection.

I hope that helps.
0
Accepted
Princy
Top achievements
Rank 2
answered on 18 Oct 2010, 01:10 PM
Hello Amit,


Adding some more information to Cori's reply. Another option is using the EmptyMessage property of RadComboBox (for that you need to set the AllowCustomText property to True). When setting EmptyMessage property, the message shows as text in the input field of the combobox when no items selected.

protected void Page_Load(object sender, EventArgs e)
{
  RadComboBox1.EmptyMessage = "Please select a country";
}


Thanks,
Princy.
Tags
ComboBox
Asked by
Amit
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or