Sarath
Sarath

Reputation: 2844

telerik MVC Grid Control - Looping through all the columns

How do I loop through all the columns in MVC Grid? From what I have seems in all the samples it seems that the columns are static. In my case it is dynamic and I want set the property at run time.

Is it possible to set some property say encode for all the columns in a grid?

Upvotes: 1

Views: 1495

Answers (1)

Sarath
Sarath

Reputation: 2844

Well it was easy once I noted that for loop can be embedded in the columns section

Html.Telerik().Grid(Model.GetDataTable()).Name("MyTestGrid").Pageable().Sortable().Filterable().Groupable().Columns(
    columns=>
    {
        foreach (var column in Model.GetDataTable().Columns)
        {
            columns.Bound(column.ToString()).Encoded(false);
        }
    }
    ).Render();

Upvotes: 1

Related Questions