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

Unable to add empty item in combobox on prerender

2 Answers 178 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
a.wilks
Top achievements
Rank 1
a.wilks asked on 12 Sep 2012, 05:10 AM
I load a RadCombo box via a store procedure.  To that list I want to add an "All" item at position 0.

I tried doing it this way:

 

protected void rcbYear_PreRender(object sender, EventArgs e)
        {
            RadComboBox combo = sender as RadComboBox;
            if (ViewState[combo.ClientID] != null)
            {
                var rcbi = new RadComboBoxItem();
                rcbi.Attributes.Add("0", "All");
                combo.Items.Insert(0, rcbi);
                combo.DataBind();
            }
        }

I verified that when the combo box comes in has the values from the store proc.  The method runs normally but the combo ends with the same items as when it came in.

Any ideas?

2 Answers, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 12 Sep 2012, 05:46 AM
Hi Angela,

I have tried the following at my end, and it works just as is should. The item is added properly to the Items collection of RadComboBox.
<telerik:RadComboBox ID="RadComboBox1" runat="server">
    <Items>
        <telerik:RadComboBoxItem Text="1" />
        <telerik:RadComboBoxItem Text="2" />
    </Items>
</telerik:RadComboBox>
protected void Page_PreRender(object sender, EventArgs e)
{
    var rcbi = new RadComboBoxItem();
    rcbi.Attributes.Add("0", "All");
    rcbi.Text = "All";
    rcbi.Value = "All";
    RadComboBox1.Items.Insert(0, rcbi);
}

Let me know if I am missing something.

Kind regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
a.wilks
Top achievements
Rank 1
answered on 12 Sep 2012, 06:14 AM
It worked!  Thank you for the very fast reply.
Tags
ComboBox
Asked by
a.wilks
Top achievements
Rank 1
Answers by
Ivana
Telerik team
a.wilks
Top achievements
Rank 1
Share this question
or