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

[Solved] Binding to List<string>

2 Answers 151 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.
MarcSimkin
Top achievements
Rank 1
MarcSimkin asked on 28 Oct 2010, 08:11 PM
I have a model that contains a property of type List<string>.  When I bind that property to the grid, all the grid displays is column called length, and then a row for for each item in the list, that is the length of the string.

I would like the grid to display the string and not the string length.

I would also like to add a two additional columns, a check box, and a button to control deleting either a group of items, or a single item.

Here is the code I'm using to do the binding:

<%
    Html.Telerik().Grid<string>()
        .Name("grdRoles")
        .BindTo(Model.Roles)
        .Render();
 %>

Thanks

2 Answers, 1 is accepted

Sort by
0
Arjen
Top achievements
Rank 1
answered on 23 Nov 2010, 09:44 AM
I actually have the same problem. I would like to bind a List<string> to the grid as well and ran into the same issue.

An workaround would be to wrap the string value in a class of its own, but i would rather bind it directly.
0
Borislav
Top achievements
Rank 1
answered on 13 Dec 2010, 10:53 PM
// in controller
      List<string> results = new List<string>();
      results.Add("Admin");
      results.Add("Super User");
      results.Add("Guest");
      ViewData["results"] = (IEnumerable<string>)results;

// in view:
    <% Html.Telerik().Grid((IEnumerable<string>)ViewData["results"])
         .Name("RolesGrid")
         .Columns(column =>
           {
             column.Bound("").Title("Role");
           })
         .Render(); %>
Tags
Grid
Asked by
MarcSimkin
Top achievements
Rank 1
Answers by
Arjen
Top achievements
Rank 1
Borislav
Top achievements
Rank 1
Share this question
or