2016-04-22 42 views
0
的每一行

我使用兩個Telerik的MVC網格和加入一種網格到其他的選擇的值I要爲第二柵格中的每一行顯示的組合框。我已經成功地將在數據綁定是和執行JS的功能,但是這會增加組合框中只有第一排初始化組合框爲Telerik的MVC網格

// Hows second Grid looking 

@(Html.Kendo().Grid<MyModel>() 
         .Name("SecondGrid") 
         .Columns(columns => 
         { 
          columns.Bound(p => p.Id).Hidden(true); 
          columns.Bound(p => p.ForeName).Title("First Name"); 
          columns.Bound(p => p.SurName).Title("Last Name"); 
          columns.Bound(p => p.Dept); 
          columns.Bound(p => p.Dob).Format("{0:dd/mm/yyyy}"); 
          columns.Bound(p => p.Relationshiptype).Title("Relationship").Template(@<text></text>).HtmlAttributes(new { @class = "templateCell" }).ClientTemplate(

                      Html.Kendo().ComboBox() 
                         .Name("Relationshiptype") 
                         .Placeholder("Select relationship...") 
                         .DataTextField("Text") 
                         .DataValueField("Value") 
                         .BindTo(new List<SelectListItem>() { 
                          new SelectListItem() { 
                          Text = "Husband", Value = "1" 
                          }, 
                          new SelectListItem() { 
                          Text = "Wife", Value = "2" 
                          }, 
                          new SelectListItem() { 
                          Text = "Other relative", Value = "3" 
                          }, 
                          new SelectListItem() { 
                          Text = "Other non relative ", Value = "4" 
                          } 
                         }).ToClientTemplate().ToString()); 

          columns.Command(command => command.Custom("Deselect").Click("removePupil")).Width(180); 
         }) 
              .Events(ev => ev.DataBound("initCombo")) 



       ) 




// Here is my InitCombo function 

function initCombo(e) { 
    $(".templateCell").each(function() { 
     eval($(this).children("script").last().html()); 
    }); 
} 

請幫我解決這問題。其次,我將如何遍歷並獲取組合的選定值以及其他行值。

謝謝

回答

1

我建議你只使用Template方法創建模板。就像在劍道文檔中一樣 - How to Customize the Way Properties Are Displayed in Grid-Bound Column

接下來,請注意,您應該爲頁面上創建的每個小部件使用唯一的ID。因此,名稱值應該對每一行都是唯一的。通過將其分配給字符串,呈現的DOM元素將具有相同的ID。

提供示例的更詳細的響應可在論壇主題中找到,其中提出了相同的問題 - Initialize Combobox for each row of Telerik MVC Grid