编辑动态生成的Telerikmvc3网格

时间:2012-08-01 06:58:03

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

我有一个动态生成的MVC3网格,它是从ViewModel填充的。我需要在网格中添加编辑功能,甚至无法进入编辑模式。

此外,我需要能够只读一些列。

我的代码如下:

@(Html.Telerik()
    .Grid<System.Data.DataRow>(Model.Data.Rows.Cast<System.Data.DataRow>())
    .HtmlAttributes(new { style = "width: 2500px" })
    .Name("Grid")
        .ToolBar(tb => tb.Template("Outstanding Orders"))
        .DataKeys(dataKeys => dataKeys.Add("DeliveryID"))
    .Columns(columns =>
    {
        columns.Command(commands =>
        {
            commands.Edit().ButtonType(GridButtonType.ImageAndText)
                .HtmlAttributes( 
                new
                {
                    style = "width: 60px; min-width: 40px; background: #0066FF"
                });
        }).Width(100).Title("Commands");
        columns.Command(commandbutton =>
        {
            commandbutton.Select().ButtonType(GridButtonType.ImageAndText)
                .HtmlAttributes(
                new
                {
                    style = "width: 60px; min-width: 40px; background: #0066FF"
                });

        columns.LoadSettings(Model.Columns as IEnumerable<GridColumnSettings>);
    })
    .DataBinding(dataBinding => dataBinding.Server()
                .Select("_DeliveryGrid", "Deliveries")
            .Update("Save", "Deliveries"))
    .Editable(editing => editing.Mode(GridEditMode.InLine))
    .Sortable(settings => settings.Enabled(true))
    .Scrollable(c => c.Height("9000px"))
    .EnableCustomBinding(true)
    .Resizable(resize => resize.Columns(true))
)

我的viewmodel定义

public class DeliveriesGridViewModel
{
    public DataTable Data { get; set; }
    public IEnumerable<GridColumnSettings> Columns { get; set; }
}

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

如果您绑定到 DataTable 或类似内容,请确保将列绑定到的属性不包含空格。

即。 “交货名称”应为“DeliveryName”

相关问题