1

我在我的项目中使用 Telerik 控件,任何主体都告诉如何在 Telerik 网格视图中获取选择更改事件,该事件可以在插入、编辑中填充多个列文本框。那是在 mvc3+razor(cshtml) 中。

编辑器模板代码

@model string
<table>
    <tr>
        <td>
            @(Html.Telerik().ComboBoxFor(e => e)
               .BindTo(ViewBag.pro as SelectList)
               .ClientEvents(events => events.OnChange("getproductdesc")) )
        </td>

        <td>

        </td>
        <td>
            @Html.TextBoxFor((model => model), new { id = "textbox" })

        </td>
    </tr>
</table>

<script type="text/javascript">

    function getproductdesc(e) {
       var idmodel = $(this).val();
       alert(idmodel);
       $('#textbox').val($(this).val());             
    }
</script>

网格视图代码

  @(Html.Telerik().Grid(Model)
    .Name("gdProductDetails")
    .ToolBar(commands => commands.Insert())
             .DataKeys(keys => keys.Add(c => c.Product_cd))
             .Pageable(paging =>
                    paging.PageSize(5)
                          .Style(GridPagerStyles.NextPreviousAndNumeric)
                          .Position(GridPagerPosition.Bottom))
                                   .Sortable(sorting => sorting
                    .SortMode(GridSortMode.MultipleColumn))
                    .DataBinding(databing => databing.Server()
                                      // .Select("DCProductDetails", "DeliveryChallan")
                                       .Insert("Addproduct", "DeliveryChallan")
                                       .Update("Editproduct", "DeliveryChallan")
                                       .Delete("Delete", "Home"))
    .Columns(columns =>
    {
        columns.Bound(c => c.Sl_no);/*EditorTemplateName("Product")*/
        columns.Bound(c => c.Product_cd).EditorTemplateName("product").Width(350);
        columns.Bound(c => c.Prouduc_desc).ClientTemplate("<input type='text' id='textbox'/>");        
        columns.Bound(c => c.Prod_rt);
columns.Command(commands =>
        {
            commands.Edit();
            commands.Delete();
        });
    })
  )  
</table>
</fieldset>

控制器代码

var listproduct = (from i in db.MSM_PRODUCT select i);
ViewBag.pro = new SelectList(listproduct, "PRODUCT_DESC", "PRODUCT_CD");
4

1 回答 1

0
@model string
<table>
    <tr>
        <td>
            @(Html.Telerik().ComboBoxFor(e => e)
               .BindTo(ViewBag.pro as SelectList)
               .ClientEvents(events => events.OnChange("getproductdesc")) )
        </td>

        <td>

        </td>
        <td>
            @Html.TextBoxFor((model => model), new { id = "textbox" })

        </td>
    </tr>
</table>

<script type="text/javascript">

    function getproductdesc(e) {
       var idmodel = $(this).val();
       alert(idmodel);
       $('#textbox').val($(this).val());             
    }
</script>
grid view code

  @(Html.Telerik().Grid(Model)
    .Name("gdProductDetails")
    .ToolBar(commands => commands.Insert())
             .DataKeys(keys => keys.Add(c => c.Product_cd))
             .Pageable(paging =>
                    paging.PageSize(5)
                          .Style(GridPagerStyles.NextPreviousAndNumeric)
                          .Position(GridPagerPosition.Bottom))
                                   .Sortable(sorting => sorting
                    .SortMode(GridSortMode.MultipleColumn))
                    .DataBinding(databing => databing.Server()
                                      // .Select("DCProductDetails", "DeliveryChallan")
                                       .Insert("Addproduct", "DeliveryChallan")
                                       .Update("Editproduct", "DeliveryChallan")
                                       .Delete("Delete", "Home"))
    .Columns(columns =>
    {
        columns.Bound(c => c.Sl_no);/*EditorTemplateName("Product")*/
        columns.Bound(c => c.Product_cd).EditorTemplateName("product").Width(350);
        columns.Bound(c => c.Prouduc_desc).EditorTemplateName("Product");
        columns.Bound(c => c.Prod_rt);
columns.Command(commands =>
        {
            commands.Edit();
            commands.Delete();
        });
    })
  )  
</table>
</fieldset>
函数 getproductdesc(e) { var idmodel = $(this).val(); 警报(idmodel);$('#textbox').val($(this).val()); }

创建一个带有文本框和 id 的编辑器模板,将编辑器模板分配给带有视图名称的赞赏列,在网格视图下方编写 jquery,并分配如下值 $('#textboxid').val($(this).val( ));

于 2012-04-30T10:52:07.233 回答