如何使用Telerik ComboBox的选定值过滤MVC Telerik Grid?

时间:2011-06-05 12:43:13

标签: jquery asp.net-mvc-3 telerik telerik-mvc

我有 ASP.NET MVC 3 页面( Razor ),其中包含 Telerik ComboBox Telerik Grid < / strong>即可。我无法弄清楚如何使用 jquery 从组合框中获取值,然后使用该值来过滤(或重新绑定)网格数据。

我的 Telerik ComboBox 加载了 * category_id * * category_name * ,我已对其进行编码,以便自行过滤当我输入category_name直到找到完美匹配或我选择一个项目时,我会在运行中。

有关最佳方法的任何指导,或有关简化jquery的提示( jquery的intellisense ?)将不胜感激。

以下是导致错误的jquery代码的一个代码部分,并且页面不会加载任何数据。错误消息(来自firebug)是:$(“#Customers”)。data(“tComboBox”)未定义,但我完全按照Telerik网站上的说明进行操作,当我查看页面源时,我看到了这个:

 jQuery('#Categories').tComboBox...snipped the  rest

这是我失败的功能:

 function dataBinding(args) {
   var categoryName = $("#Customers").data("tComboBox").value();
   args.data = $.extend(args.data, { categoryName: categoryName });
}

1 个答案:

答案 0 :(得分:1)

你可以为jQuery添加智能感知,请阅读这篇文章:

jQuery Intellisense Setup

要从Telerik组合框中检索所选值,请执行以下操作:

查看标记

// Assumed defenition of the combobox
<%= Html.Telerik().DropDownList()
        .Name("DropDownList")
        .BindTo(new SelectList(Model, "ProductID", "ProductName"))
        .HtmlAttributes(new { style = "width: 200px; float: left; clear:both; margin-bottom: 230px;" })
%>

客户端脚本

// Will Get Selected Text
$("#DropDownList").data("tDropDownList").text()
// Will Get Selected Value
$("#DropDownList").data("tDropDownList").value()

进一步澄清$("#DropDownList").data("tDropDownList").text()中的“DropDownList”是帮助方法(Html.Telerik().DropDownList().Name("DropDownList"))中指定给控件的名称,因此您应该将上面发布的代码更改为$(“#客户“)。数据(” tCustomers “)。value(),它应该有效。

PS:有关Telerik ASP.NET MVC ComboBox API的更多信息,请访问Telerik API