I am using the telerik ASP.NET MVC Grid template and currently have several check boxes (one for each column in a table). This way the user can select which columns they want to be displayed in the grid.
Instead of manually writing out each checkbox on the view, can I use a foreach loop to have each check box generated on the view for me?
I’m looking to replace something like this:
<%= Html.CheckBox("SomeColumnID", false, "Something")%><label for="SomeColumnID">Some Label</label>
// . . . over and over again for each column
With something like this:
<%foreach (ColumnInGivenDB)
{%>
<%= Html.CheckBox(SomeColumnIDVariable, false, SomeOtherVariable)%><label for=SomeColumnIDVariable>Some Label</label>
<%}%>
Any ideas?
It seems you’re almost there, but missing binding to the
Modelor one if its properties part.You mean something like the following?
As an example I am binding to a simple object with UserName property