网格中基于行值的 Telerik MVC 组合框?
我需要一个带有组合框(处于编辑模式)的 Telerik MVC 网格,该组合框根据每行中的条件进行填充。因此,当我单击一行上的“编辑”时,生成的组合框中将包含与其他行中的翻译器组合框不同的项目。我认为这一行应该按需加载,但我无法弄清楚如何在没有编辑器模板的情况下在网格中创建组合框。看起来我无法将参数传递给编辑器模板。
这是此的用例: 想象一下,我有一个网格中带有翻译器的语言列表。编辑每一行时,将显示一个翻译器组合框,其中仅包含该特定语言的翻译器。因此,法语将有一个翻译器组合框,其中包含 Pierre、Francois 和 Jacque 等名字,但西班牙语将有 Jose、Mario 等名字,可能还包括 Pierre,因为他会说法语和西班牙语。
关于如何使用 Telerik MVC Grid 和 Combobox 实现这一目标有什么想法吗?
提前致谢, 史蒂夫
更新: 阿塔纳斯, 您有机会提供一个可行的示例吗?我收到错误。这是我基于您的代码的 javascript:
function TaskGrid_OnEdit(e)
{
var combobox = $(e.row).find("#ComboBoxId").data("tComboBox");
//var values = getValuesForDataItem(e.dataItem); // get the values for the current data item
var values =
[
{ Text:"Product 1", Value:"1" },
{ Text:"Product 2", Value:"2" },
{ Text:"Product 3", Value:"3" },
];
combobox.dataBind(values); // fill the combobox
}
这是编辑器模板,我没有将其绑定到此处的任何内容:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Model.Data.tblJobTask>" %>
<%: Html.Telerik().DropDownListFor(s => s.SupplierID).Name("ComboBoxId") %>
顺便说一句,编辑器模板中的模型不会映射到解决方案中的任何模型。那里的模型是否应该映射到您要填充组合的数据或填充网格的列表的模型?
史蒂夫
I need to have a Telerik MVC grid with a combobox (in edit mode) that is populated based on criteria in each row. So when I click edit on one row, the resulting combobox will have items in it that will be different than the translator combobox in other rows. I figured this row should be loaded on demand, but I can't figure out how to create a combobox in a grid without an editor template. It looks like I can't pass parameters to an editor template.
Here's the use case for this:
Imagine I have a list of languages with translators in a grid. When editing each row, a translator combobox would be displayed with only translators for that particular language. So French will have a translator combobox with names like Pierre, Francois, and Jacque, but Spanish will have names like Jose, Mario, and possibly Pierre because he speaks both French and Spanish.
Any ideas on how to achieve this with Telerik MVC Grid and Combobox?
Thanks in advance,
Steve
UPDATE:
Atanas,
Any chance you can provide a working example? I get errors. Here is my javascript based on your code:
function TaskGrid_OnEdit(e)
{
var combobox = $(e.row).find("#ComboBoxId").data("tComboBox");
//var values = getValuesForDataItem(e.dataItem); // get the values for the current data item
var values =
[
{ Text:"Product 1", Value:"1" },
{ Text:"Product 2", Value:"2" },
{ Text:"Product 3", Value:"3" },
];
combobox.dataBind(values); // fill the combobox
}
Here is the editor template, I don't bind it to anything here:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Model.Data.tblJobTask>" %>
<%: Html.Telerik().DropDownListFor(s => s.SupplierID).Name("ComboBoxId") %>
By the way, the model in your editor template doesn't map to any models you have in the solution. Should the model there be mapped to the data you are populating the combo with or the model of the list that's populating the grid?
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在网格中嵌入组合框,您可以检查 这个代码库项目(只需用组合框替换下拉列表)。不过,您仍然需要使用编辑器模板。
为了使用特定于当前行的值填充组合框,您可以使用 OnEdit 网格事件。在那里,您可以使用其 dataBind 方法(将其绑定到客户端)或调用其 重新加载方法使用ajax来填充它。这是一些代码:
For embedding a combobox in a grid you can check this code library project (just replace the dropdownlist with a combobox). You still need to use an editor template though.
In order to populate the combobox with values specific to the current row you can use the OnEdit event of the grid. There you can setup the combobox using its dataBind method (to bind it client-side) or call its reload method to fill it using ajax. Here is some code: