Reputation: 4126
Now i have tryed to solve the problem for several hours and im about to give up...
I am using MVC 3 grid kontrol from Telerik. In my grid i want dropdownlists selected item to be corresponding to Role of the user. Dropdownlist have all the User Roles.
@(Html.Telerik().Grid(Model)
.Name("Grid").TableHtmlAttributes(new { width="800"})
.Columns(columns =>
{
//if (userIsInWhateverRole){
// columns.Template(o => Html.Action(GenerateYourLinkStuffHere));
//}
columns.Bound(o => o.Name).Width(150);
columns.Bound(o => o.Email).Width(120);
columns.Template(
@<text>
@Html.DropDownList(item.Role, (IEnumerable<SelectListItem>)item.Roles)
@Html.DropDownListFor(x => item.Role, (IEnumerable<SelectListItem>)item.Roles)
</text>
).Width(120);
})
.Sortable()
.Scrollable()
.Groupable()
.Filterable()
.Pageable(paging => paging.PageSize(5))
)
Upvotes: 4
Views: 4503
Reputation: 162
So, instead of
@Html.DropDownListFor(x => item.Role, (IEnumerable<SelectListItem>)item.Roles)
You should do this
@Html.DropDownListFor(x => item.Role, new SelectList(item.Roles, item.Role))
And that should solve your problem.
Upvotes: 1
Reputation: 6060
you should try something like this
in your model, add an attribute [UIHint("Role")]
for Role property (keep it simple string)
load the grid as it is
columns.Bound(o => o.Name).Width(150);
columns.Bound(o => o.Email).Width(120);
columns.Bound(o => o.Roll).Width(120);
add a view named Role.cshtml
inside of EditorTemplates (this is a folder, directory like as View/(controller-specific-folder)/EditorTemplates)
and finally put your dropdown in the Role.cshtml
view.
For more details http://www.telerik.com/community/forums/aspnet-mvc/grid/combo-box-in-grid.aspx sample http://www.telerik.com/ClientsFiles/327900_TelerikMvcGridEditingDropdown.zip
Upvotes: 6