Inserting new item into RadCombobox

3 posts, 2 answers
  1. Amit
    Amit avatar
    88 posts
    Member since:
    Sep 2010

    Posted 18 Oct 2010 Link to this post

    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. Answer
    Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 18 Oct 2010 Link to this post

    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.
  3. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Oct 2010 Link to this post

    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.
Back to Top