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

Related ComboBoxes - Server Side

2 Answers 107 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Nick J
Top achievements
Rank 1
Nick J asked on 13 Jul 2009, 07:06 PM
Hi, does anyone have an example they could post on using related combo boxes using code-behind.

The example on site uses client-side events and i'm struggling to get this working using just code-behind - I can't retrive the text or value from the first combo box in ItemsRequested method for the second combo-box, it just returns a blank string or NULL.

Any examples of how to achieve this would be cool!

Thanks,
N

2 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 14 Jul 2009, 08:46 AM
Hello Nick J,

All other control properties' values are invalid in the server-side ItemsRequested event handler of a RadComboBox. Only the Text and SelectedValue of the sender ComboBox are valid.

You need to pass the SelectedValue of the previous ComboBox to the ItemsRequested event handler of the second one and so on and this, without client code is unachievable. You could to at the client-side by using the Context object, which is available in the client-side ItemsRequesting event handler (please read more about the approach here).

Below is a simple example of the approach:

[ASPX]
<telerik:RadComboBox ID="RadComboBox1" runat="server" EnableLoadOnDemand="true"  
    OnItemsRequested="RadComboBox1_ItemsRequested"
</telerik:RadComboBox> 
<telerik:RadComboBox ID="RadComboBox2" runat="server" EnableLoadOnDemand="true"  
    OnClientItemsRequesting="onItemsRequesting" 
    OnItemsRequested="RadComboBox2_ItemsRequested"
</telerik:RadComboBox> 
<script type="text/javascript"
    function onItemsRequesting(sender, eventArgs) { 
        var previousComboBox = $find("RadComboBox1"); 
 
        eventArgs.get_context()["previousComboBoxValue"] = 
            previousComboBox.get_value(); 
    } 
</script> 
[C#]
protected void RadComboBox2_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) 
    string value = e.Context["previousComboBoxValue"].ToString(); 
[VB]
Protected Sub RadComboBox2_ItemsRequested(o As Object, e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) 
    Dim value As String = e.Context("previousComboBoxValue").ToString() 
End Sub 

All the best,
Simon
the Telerik team

Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
0
Nick J
Top achievements
Rank 1
answered on 17 Jul 2009, 09:31 AM
Thanks!

That worked a treat!
Tags
ComboBox
Asked by
Nick J
Top achievements
Rank 1
Answers by
Simon
Telerik team
Nick J
Top achievements
Rank 1
Share this question
or