This question is locked. New answers and comments are not allowed.
Hi, I've three comboboxes in cascade, and the three are properties of a ViewModel:
The View:
Using the OnLoad event, the comboboxes get the values:
The controller:
The problem is when I change the parent combo, the cascadeTo combo set it's text to the value of the property, and I was trying to chage this behavior in the OnChange event of the parent, but doesn't work. If you have a solution to this, it would be great.
Eduardo
public class MyOrder { public int Category { get; set; } public int Product { get; set; } public int Orders { get; set; } }
The View:
@( Html.Telerik().ComboBoxFor(model => model.Category) .DataBinding(binding => binding.Ajax().Select("_SelectCategory", "CascadingComboBox")) .ClientEvents(e => e.OnLoad("onLoadCombo").OnChange("onChangeCombo")) .CascadeTo("Product") ) <br /> @( Html.Telerik().ComboBoxFor(model => model.Product) .DataBinding(binding => binding.Ajax().Select("_SelectProduct", "CascadingComboBox")) .CascadeTo("Orders") .ClientEvents(e => e.OnLoad("onLoadCombo").OnChange("onChangeCombo")) ) <br /> @( Html.Telerik().ComboBoxFor(model => model.Orders) .DataBinding(binding => binding.Ajax().Select("_SelectOrders", "CascadingComboBox")) .ClientEvents(e => e.OnLoad("onLoadCombo")) )
Using the OnLoad event, the comboboxes get the values:
function onLoadCombo(e) { $(e.target).data('tComboBox').reload(); $(e.target).data('tComboBox').enable(); }
The controller:
public class CascadingComboBoxController : Controller { readonly Entities context = new Entities(); public ActionResult Index() { return View(new MyOrder {Product = 24, Category = 1, Orders = 10352}); } public JsonResult _SelectCategory() { return Json(new SelectList(context.Categories, "CategoryID", "CategoryName"), JsonRequestBehavior.AllowGet); } public JsonResult _SelectProduct(int? Category) { return Json( new SelectList(context.Products.Where(cat => !Category.HasValue || cat.CategoryID == Category), "ProductID", "ProductName"), JsonRequestBehavior.AllowGet); } public JsonResult _SelectOrders(int? Product) { return Json( new SelectList( context.Order_Details.Where(order => !Product.HasValue || order.ProductID == Product), "OrderID", "OrderID"), JsonRequestBehavior.AllowGet); } }
The problem is when I change the parent combo, the cascadeTo combo set it's text to the value of the property, and I was trying to chage this behavior in the OnChange event of the parent, but doesn't work. If you have a solution to this, it would be great.
Eduardo