Telerik: Grid-Dropdown

Please see my other Telerik articles.

Using dropdowns within grids

In this article I’ll demonstrate how to use a dropdown within a Telerik grid.

First, I’ll begin with the View Model used with CRUD operations on the grid.

1.Telerik-Grid-Dropdown

Regarding the first View Model, you’ll notice the UIHint decoration.
This attribute instructs the website to use the following partial view when displaying this field.

3.Telerik-Grid-Dropdown

For the dropdown, I define a property which itself is another View Model.

Notice in the partial view the same view model is references for the dropdown property.

With my view models defined and partial view for the dropdown’s UI ready, I’ll instruct the controller to populate the dropdown when the view first loads.

4.Telerik-Grid-Dropdown

Notice once again the View Model used in the population.

Now I’m ready to define this field in the View within the grid’s definition.

5.Telerik-Grid-Dropdown

Notice for the LINQ expression “c => c.Jurisdiction,” I define a template which points to the view model property of “Jurisdiction,” then that view model’s property “Name.”

6.Telerik-Grid-Dropdown

Finally, I’ll set the dropdown’s default value when the user click’s “Add new record,” or “Edit.”

7.Telerik-Grid-Dropdown

Ensure the name passed to ViewData[] matches that of the assignment within the previous action used to populate the dropdown.

Now we can see the dropdown working with the grid.

8.Telerik-Grid-Dropdown9.Telerik-Grid-Dropdown10.Telerik-Grid-Dropdown