New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

RadComboBox items are not accessible on the server-side when loading them on demand

DESCRIPTION

RadComboBox items loaded on demand using the ItemsRequested event, ASMX WebService or WCF WebService do not exist on the server, therefore they cannot be accessed.

The following properties and methods will not yield results:

  • FindItemByText - returns null / Nothing
  • FindItemByValue - returns null / Nothing
  • SelectedItem - returns null / Nothing
  • SelectedIndex - returns -1

The purpose of the Load On Demand functionality is to boost the loading speed by using little to no ViewState related information.

SOLUTION

The only information that will be persisted is the Text and Value.

If using the SelectedIndexChanged event of the Combo, the Text and Value will be available in the event arguments (e.Text and e.Value)

In other events, you can access the Text and Value through the Text and SelectedValue properties of the RadComboBox instance.

Example Combo Markup

ASP.NET
<telerik:RadComboBox ID="RadComboBox1" runat="server" RenderMode="Lightweight" EnableLoadOnDemand="true" 
    AutoPostBack="true"
    OnItemsRequested="RadComboBox1_ItemsRequested"
    OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
</telerik:RadComboBox>

Example ItemsRequested event

C#
protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    RadComboBox combo = (RadComboBox)sender;

    // DataTable with Dummy data
    var dt = new DataTable();
    dt.Columns.Add("ID", typeof(int));
    dt.Columns.Add("Name", typeof(string));
    dt.Columns.Add("Description", typeof(string));

    for (int i = 0; i < 10; i++)
    {
        var newRow = dt.NewRow();

        newRow["ID"] = i;
        newRow["Name"] = "Name " + i;
        newRow["Description"] = "Desc " + i;

        dt.Rows.Add(newRow);
    }

    // Required by the Load On Demand functionality
    // Loop through the data
    foreach (DataRow row in dt.Rows)
    {
        // Create Combo Item and pass the Text as parameter
        RadComboBoxItem item = new RadComboBoxItem();

        // Populate the Text and Value properties
        item.Text = row["Name"].ToString(); // Needed to access the Text
        item.Value = row["ID"].ToString(); // Needed to access the Value

        // add the Combo Item to the Combo's Items collection.
        combo.Items.Add(item);
    }
}

Accessing the Text and Value on server side using the Combo's SelectedIndexChanged event

C#
protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    var text = e.Text;
    var value = e.Value;
    // OR 
    var combo = (RadComboBox)sender;
    var text2 = combo.Text;
    var value2 = combo.SelectedValue;
}

Accessing the Text and Value on server side in a Button Click

C#
protected void RadButton1_Click(object sender, EventArgs e)
{
    var text = RadComboBox1.Text;
    var selectedValue = RadComboBox1.SelectedValue;
}

See Also

In this article
DESCRIPTIONSOLUTIONSee Also
Not finding the help you need?
Contact Support