Setting an initial value in RadComboBox while using Load on Demand

4 posts, 0 answers
  1. Andrea
    Andrea avatar
    13 posts
    Member since:
    Nov 2008

    Posted 06 Dec 2012 Link to this post

    My combo is empty until I click the dropdown (items request event is fire): so what is the best strategy to set an initial item (value and text) in RadComboBox while using Loading on Demand?

    Thx

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Dec 2012 Link to this post

    Hi,

    One suggestion is that you can add an initial RadComboBoxItem as follows.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" EnableLoadOnDemand="True" MarkFirstMatch="True" OnItemsRequested="RadComboBox1_ItemsRequested">
    </telerik:RadComboBox>

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
       //adding initial RadComboBoxItem
        if (!Page.IsPostBack)
        {
            RadComboBoxItem item = new RadComboBoxItem();
            item.Text = "initial item";
            item.Value = "0";
            RadComboBox1.Items.Add(item);
        }
    }
    protected void RadComboBox1_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
    {
        //Your code
    }

    Please take a look into this for more information.

    Hope this helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rahul
    Rahul avatar
    39 posts
    Member since:
    Jan 2014

    Posted 12 Jan 2014 Link to this post

    Hi Princy,
                  How can do it client side on page load.
    Thanks,
    Rahul
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Jan 2014 Link to this post

    Hi Rahul,

    Please have a look into the following code snippet to add a new item to the RadComboBox from the client side.

    JavaScript:
    <script type="text/javascript">
        function pageLoad() {
            var combo = $find("<%= RadComboBox1.ClientID %>");
            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
            comboItem.set_text("New Item");
            combo.trackChanges();
            combo.get_items().add(comboItem);
            combo.commitChanges();  
        }
    </script>

    Thanks,
    Princy.
Back to Top