0

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

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

我的代码如下:

@(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))
)

我的视图模型定义

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

谢谢您的帮助

4

1 回答 1

1

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

即“Delivery Name”应该是“DeliveryName”

于 2012-08-06T21:17:05.990 回答