This is a migrated thread and some comments may be shown as answers.

[Solved] How to access column dynamically?

1 Answer 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bala
Top achievements
Rank 1
Bala asked on 14 Apr 2011, 01:57 PM
Hi,
We are using MVC with Telerik component. In our case, we have a grid and with dynamic columns. In normal applications we access the column in code behind. But in MVC , shall we use server side code to access the particular columns. If it so, please give us sample code to access the particular columns.

The following are the code sample what we have used in our project,

 

 

 

 

<% Html.Telerik().Grid(Model.objStudentCollection)

 

.Name(

 

"ExamGrid")

 

 

.DataKeys(keys =>

 

{

 

keys.Add(p => p.StudentID);

 

})

 

.Pageable(p => p.PageSize(50))

 

.Scrollable(p => p.Height(500))

 

.Columns(columns =>

 

{

 

columns.Template(o =>

 

 

"<input type='checkbox' name='checkedRecords' value='<#= StudentID #>' />")

 

 

.Title(

 

 

"<input id='mastercheckbox' type='checkbox' />") // add checkbox to header

 

 

 

 

 

 

 

 

 

.HeaderHtmlAttributes(

 

 

new { style = "text-align:center;" })

 

 

.Width(50)

 

.HtmlAttributes(

 

 

new { style = "text-align:center;" });

 

 

columns.Bound(o => o.StudentID).Width(150).Title(

 

 

 

 

"ID");

 

 

columns.Bound(o => o.StudentName).Width(150).Title

 

(

 

 

"Name:");

 

 

 

 

 

 

 

 

columns.Bound(o=>o.SEmail).Width(150).Title("Email").Hidden();// Here want to hide Dynamically 

 

 

 

})

 

.Pageable(paging => paging.PageSize(5))

 

 

 

.Selectable()

 

.Scrollable()

 

.Sortable(sort => sort.SortMode(

 

 

GridSortMode.MultipleColumn))

 

 

.Render();

 

 

 

 

 

%>


Regards
Dhandapani

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 14 Apr 2011, 02:42 PM
Hi Bala,

 You can use a regular if statement when defining your column. After all it is C# code. Here is a quick example:


.Columns(columns =>
{
       if (/* code to determine whether the column should be hidden*/)
       {
             columns.Bound(c => c.Property).Hidden(true);
       }
        else
        {
            columns.Bound(c => c.Property);
        }
});

All the best,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Bala
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or