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

Setting an initial value in RadComboBox while using Load on Demand

3 Answers 267 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Andrea
Top achievements
Rank 1
Andrea asked on 06 Dec 2012, 11:39 PM

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

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Dec 2012, 04:13 AM
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.
0
Rahul
Top achievements
Rank 1
answered on 12 Jan 2014, 07:17 AM
Hi Princy,
              How can do it client side on page load.
Thanks,
Rahul
0
Princy
Top achievements
Rank 2
answered on 13 Jan 2014, 04:12 AM
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.
Tags
ComboBox
Asked by
Andrea
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rahul
Top achievements
Rank 1
Share this question
or