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

[Solved] Telerik Grid for Asp.net MVC-Editing Templates

0 Answers 154 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.
devika godse
Top achievements
Rank 1
devika godse asked on 18 May 2010, 12:42 PM
I have a grid for displaying Product details containing Name,Price and Category.

View-
<%= Html.Telerik().Grid(Model)
        .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.Id))
        .ToolBar(commands => commands.Insert())
        .DataBinding(dataBinding => dataBinding.Server()
                   .Select("Index", "Product")
                   .Insert("Insert", "Product")
                   .Update("Save", "Product")
                   .Delete("Delete", "Product"))
        .Columns(columns =>
        {
            columns.Bound(c => c.Name);
            columns.Bound(c => c.Price );
            columns.Bound(c => c.Category.Name);
            columns.Command(commands =>
            {
                commands.Edit();
                commands.Delete();
            }).Width(180).Title("Commands");
        })
.Sortable()      
.Scrollable()        
.Pageable()
%>

In Controller-
[PopulateCategory]
public ActionResult Index()
        {            
            return View(GetAllProducts());
        }

I have written an attribute for populating Category :-

public class PopulateCategoryAttribute:ActionFilterAttribute
    {
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            filterContext.Controller.ViewData["Category"] =GetAllCategory();
        }
    }

And created a usercontrol DDLCategory.ascx

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Category>" %>
<%= Html.DropDownList(null, new SelectList((IEnumerable)ViewData["Category"], "Id", "Name"))%>

Now when I click on Edit Button I want Category column to be comboBox column. As shown in "http://demos.telerik.com/aspnet-mvc/Grid/DisplayAndEditTemplates/10248?Grid-mode=edit" How do I do this???

Currently when I click Edit Button Controller's Index method is called and then PopulateCategoryAttribute's OnResultExecuting method is called. This will populate Categories but to display comboBox in Category column how do I call the usercontrol.

Tags
Grid
Asked by
devika godse
Top achievements
Rank 1
Share this question
or