在 Telerik RadGrid 上以编程方式将列设置为只读时出现问题

发布于 2024-08-10 21:49:43 字数 510 浏览 3 评论 0原文

我试图在运行时使用 Page_Load 处理程序中的以下代码动态使某些列只读:

                GridNumericColumn gncp = grid.MasterTableView.GetColumn("ActualProduction") as GridNumericColumn;
                if (gncp != null)
                {
                    gncp.ReadOnly = true;
                }

但是,上述代码仅在该列是网格中的最后一列时才有效。如果我尝试使用倒数第二个或更左边的列,则该行上的“编辑”命令将不再起作用。没有抛出异常,并且 EditCommand 被触发,但这就是聚会停止的地方。

我怀疑我可能在页面生命周期中错误的位置修改了网格,但我真的不想开始通过反复试验来寻找正确的位置。我使用 grid_NeedDataSource 绑定网格,而不是在页面加载中。有什么想法吗?

I'm trying to dynamically make certain columns readonly at runtime using the following code in my Page_Load handler:

                GridNumericColumn gncp = grid.MasterTableView.GetColumn("ActualProduction") as GridNumericColumn;
                if (gncp != null)
                {
                    gncp.ReadOnly = true;
                }

However, the above code only works if the column is the last column in the grid. If I try with the second to last, or columns further left, the Edit command on the row no longer works. No exception is thrown, and the EditCommand fires, but that's where the party stops.

I suspect I may be modifying the grid in the wrong place in the page life cycle, but I really don't want to start looking for the right place by trial and error. I bind my grid using grid_NeedDataSource, not in page load. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

信愁 2024-08-17 21:49:43

尝试在网格的 PreRender 处理程序中设置只读状态。我认为这是更合适的地方。有关列自定义的更多信息,请参见此处

迪克

Try setting the readonly status inside the PreRender handler of the grid. I think this is more appropriate place to do that. More about columns customization here.

Dick

桃气十足 2024-08-17 21:49:43

这就是我用于 ASP.NET MVC 3 Telerik Grid 的内容。我在更改列的顺序时没有遇到问题。显然我正在使用 Razor 视图引擎。我希望这有帮助。

  @(Html.Telerik().Grid(Model)
    .Name("catGrid")
    .DataKeys(k => k.Add(o => o.cat_id))
    .Columns(columns =>  
    {
        columns.Bound(m => m.cat_id).ReadOnly(true).Visible(false);
        columns.Bound(m => m.tenant_id).ReadOnly(true).Visible(false);
        columns.Bound(m => m.date_added).ReadOnly(true).Visible(false);
        columns.Bound(m => m.category_name).Title("Category Name").Width(350);
        columns.Bound(m => m.status_cd).Title("Status").Width(150);
        columns.Command(c => 
        {
            c.Edit();
            c.Delete();
        }).Width(250);
    })
    .DataBinding(b => b.Ajax()
        .Select("AjaxGridSelect", "Category")
        .Insert("GridInsert", "Category")
        .Update("GridUpdate", "Category")
        .Delete("GridDelete", "Category")
    )
    .ToolBar(t => 
    {
        t.Insert();
    })
    .Pageable(paging => paging.PageSize(20)
        .Style(GridPagerStyles.NextPreviousAndDropDown)
        .Position(GridPagerPosition.Both)
    )
    .Sortable()
    .Filterable()
  )

this is what I'm using for ASP.NET MVC 3 Telerik Grid. I haven't had problems changing the order of the columns. Obviously I'm using the Razor view engine. I hope this helps.

  @(Html.Telerik().Grid(Model)
    .Name("catGrid")
    .DataKeys(k => k.Add(o => o.cat_id))
    .Columns(columns =>  
    {
        columns.Bound(m => m.cat_id).ReadOnly(true).Visible(false);
        columns.Bound(m => m.tenant_id).ReadOnly(true).Visible(false);
        columns.Bound(m => m.date_added).ReadOnly(true).Visible(false);
        columns.Bound(m => m.category_name).Title("Category Name").Width(350);
        columns.Bound(m => m.status_cd).Title("Status").Width(150);
        columns.Command(c => 
        {
            c.Edit();
            c.Delete();
        }).Width(250);
    })
    .DataBinding(b => b.Ajax()
        .Select("AjaxGridSelect", "Category")
        .Insert("GridInsert", "Category")
        .Update("GridUpdate", "Category")
        .Delete("GridDelete", "Category")
    )
    .ToolBar(t => 
    {
        t.Insert();
    })
    .Pageable(paging => paging.PageSize(20)
        .Style(GridPagerStyles.NextPreviousAndDropDown)
        .Position(GridPagerPosition.Both)
    )
    .Sortable()
    .Filterable()
  )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文