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

Related ComboBoxes - Second Combo Not Showing Values

3 Answers 58 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Chris T.
Top achievements
Rank 1
Chris T. asked on 15 Dec 2011, 04:08 PM
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:

<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()));
        }
      }
    }
  }
}

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Dec 2011, 05:48 AM
Hello,

Take a look into the following demo.
ComboBox / Related ComboBoxes

Thanks,
Princy.
0
Chris T.
Top achievements
Rank 1
answered on 16 Dec 2011, 02:27 PM
Princy,

Thanks for your response.  Unfortunately, that's where I got most of the code I posted. :)

The frustrating thing is that the data IS getting to the client side.  Fiddler shows it in transit, and Javascript in the ItemsLoaded shows all my items.  Something/someone (me?) is just not telling the dropdown box itself about it. :/

-Chris

0
Dimitar Terziev
Telerik team
answered on 19 Dec 2011, 03:21 PM
Hi Chris,

The experienced behavior seems very strange, especially if the items are really transferred from the server. In order to troubleshoot this issue, please provide a live URL to your page or open a support ticket and send a runnable sample.

Regards,
Dimitar Terziev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
ComboBox
Asked by
Chris T.
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Chris T.
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or