Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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()
  )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top