I feel like I'm missing something here, but I can't seem to get a pair of related comboboxes working.
When I select something in the primary combo, I get the proper callback, and everything seems to flow correctly. I threw an alert in the javascript "ItemsLoaded", and the secondary combo has items. But when the secondary drop down opens, it is blank. Empty. Nada.
Grrrr. Here's the code:
From ucOffenseEdit.ascx (user control for a RadGrid edit/add), the ComboBoxes themselves:
Now the javascript. For simplicity sake, I'm putting it right in the page where the RadGrid lives. Eventually (when it works), I'll emit it from the user control's codebehind:
Finally, the codebehind from the user control:
When I select something in the primary combo, I get the proper callback, and everything seems to flow correctly. I threw an alert in the javascript "ItemsLoaded", and the secondary combo has items. But when the secondary drop down opens, it is blank. Empty. Nada.
Grrrr. Here's the code:
From ucOffenseEdit.ascx (user control for a RadGrid edit/add), the ComboBoxes themselves:
<table cellpadding="0" cellspacing="4" class="InnerContents" width="100%"> <tr> <td style="vertical-align: top" colspan="4"> <asp:Label ID="lblUCRCode" runat="server" CssClass="FieldLabel" Text="UCR Code" /> <br /> <telerik:RadComboBox ID="fldUCRCode" runat="server" Width="400px" Height="168px" SkinID="NoSizing" Filter="contains" SelectedValue='<%# Eval("UCRCodeID") %>' OnClientLoad="ComboSetFocus" OnClientSelectedIndexChanging="loadOptionalUCRCodes" OnItemsRequested="fldUCRCode_ItemsRequested" /> <br /> </td> </tr> <tr> <td style="vertical-align: top" colspan="4"> <asp:Label ID="lblUCROptionalDetailCode" runat="server" CssClass="FieldLabel" Text="Optional Detail Code" /> <br /> <telerik:RadComboBox ID="fldUCROptionalDetailCode" runat="server" EnableViewState="false" Width="400px" Height="168px" SkinID="NoSizing" Filter="contains" SelectedValue='<%# Eval("UCRCodeID") %>' OnClientItemsRequested="ItemsLoaded" OnItemsRequested="fldUCROptionalDetailCode_ItemsRequested" /> </td> </tr> ... etc. </table>Now the javascript. For simplicity sake, I'm putting it right in the page where the RadGrid lives. Eventually (when it works), I'll emit it from the user control's codebehind:
function loadOptionalUCRCodes(sender, eventArgs) { var id = sender.get_id(); var optionalCombo = $find(id.substring(0, id.length - 10) + "fldUCROptionalDetailCode"); var item = eventArgs.get_item(); optionalCombo.set_text("Loading..."); // if a UCR Code is selected... if (item.get_index() > 0) { // ...load the optional combo optionalCombo.requestItems(item.get_value(), false); } else { optionalCombo.set_text(" "); optionalCombo.clearItems(); } } function ItemsLoaded(sender, eventArgs) { if (sender.get_items().get_count() > 0) { // pre-select the first item sender.set_text(sender.get_items().getItem(0).get_text()); sender.get_items().getItem(0).highlight(); } sender.showDropDown(); } Finally, the codebehind from the user control:
protected void Page_Load(object sender, EventArgs e) { LoadUCRCodes(); if (!Page.IsCallback) { LoadOptionalUCRCodes(fldUCRCode.SelectedValue); } } protected void fldUCRCode_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) { LoadUCRCodes(); } protected void fldUCROptionalDetailCode_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) { //passes the value of the UCRCode LoadOptionalUCRCodes(e.Text); } protected void LoadUCRCodes() { if (fldUCRCode.Items.Count == 0) { fldUCRCode.Items.Add(new Telerik.Web.UI.RadComboBoxItem(string.Empty, "-1")); foreach (DAL.LookupClasses.INCUCRCodeLookupItem l in Lookups.INC.UCRCode.AllItems) { if (!l.Parent.HasValue) { fldUCRCode.Items.Add(new Telerik.Web.UI.RadComboBoxItem(l.DropDownText, l.ID.ToString())); } } } } protected void LoadOptionalUCRCodes(string UCRCodeID) { fldUCROptionalDetailCode.Items.Clear(); if (fldUCROptionalDetailCode.Items.Count == 0) { fldUCROptionalDetailCode.Items.Add(new Telerik.Web.UI.RadComboBoxItem(string.Empty, "-1")); foreach (DAL.LookupClasses.INCUCRCodeLookupItem l in Lookups.INC.UCRCode.AllItems) { if (l.Parent.HasValue) { if (l.Parent.ToString() == UCRCodeID) { fldUCROptionalDetailCode.Items.Add(new Telerik.Web.UI.RadComboBoxItem(l.DropDownText, l.ID.ToString())); } } } } }