Kendo Dropdown值到文本框

时间:2013-07-15 09:13:31

标签: asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 kendo-ui

我有kendodropdown,我想将kendodropdown中的选定值填充到文本框中,然后单击编辑按钮。我用的是mvc.razor。请帮忙。  控制器1 /厂景

     @(Html.Kendo().DropDownList()
      .Name("labeldropdown")
      .DataTextField("Tasks")
        .DataValueField("ID")
          .OptionLabel("Select label")
         .AutoBind(true)
     .HtmlAttributes(new { @style = "width: 72px;font-size:12px; " })
        .DataSource(source =>
   {   source.Read(read =>
          {
          read.Action("BindStates", "Resource");
       });
        })
        .SelectedIndex(0)
      )

<input type="button" value="New" class="k-button" id="newLabel" />
  <input type="button" value="Edit" class="k-button" id="editLabel" />

控制器1 /视图2

 <input type="button" value="OK" class="k-button" id="labelok" /><br />
  <input type="button" value="Cancel" class="k-button" id="labelcancel" />
  @Html.TextBox("labeltxt", null, new { @class = "k-textbox" })

1 个答案:

答案 0 :(得分:0)

试试这个,

@(Html.Kendo().DropDownList()
      .Name("labeldropdown")
      .DataTextField("Tasks")
        .DataValueField("ID")
          .OptionLabel("Select label")
         .AutoBind(true)
     .HtmlAttributes(new { @style = "width: 72px;font-size:12px; " })
        .DataSource(source =>
   {   source.Read(read =>
          {
          read.Action("BindStates", "Resource");
       });
        })
        .SelectedIndex(0)
      )


     @Html.TextBox("labeltxt", null, new {id = "txtText", @class = "k-textbox" })

    <input type="button" value="Edit" class="k-button" id="editLabel" />

        $("#editLabel").click(function () {

              $("#txtText").val($("#labeldropdown").data("kendoComboBox").value());
              $("#CoutryID").data("kendoComboBox").value();//This is for ID               
              $("#CoutryID").data("kendoComboBox").text();  //This is for text             
        });

所以你必须根据上面的代码设置值。