Unable to add empty item in combobox on prerender

3 posts, 0 answers
  1. a.wilks
    a.wilks avatar
    9 posts
    Member since:
    Feb 2011

    Posted 12 Sep 2012 Link to this post

    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. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 12 Sep 2012 Link to this post

    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.
  3. a.wilks
    a.wilks avatar
    9 posts
    Member since:
    Feb 2011

    Posted 12 Sep 2012 Link to this post

    It worked!  Thank you for the very fast reply.
Back to Top