Related ComboBoxes - Server Side

3 posts, 0 answers
  1. Nick J
    Nick J avatar
    2 posts
    Member since:
    Jul 2009

    Posted 13 Jul 2009 Link to this post

    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. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 14 Jul 2009 Link to this post

    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.
  3. Nick J
    Nick J avatar
    2 posts
    Member since:
    Jul 2009

    Posted 17 Jul 2009 Link to this post

    Thanks!

    That worked a treat!
Back to Top