Inserting Dropdown control in web grid in ASP.NET MVC 3.0

Locked Inserting Dropdown control in web grid in ASP.NET MVC 3.0

  • jeudi 3 mai 2012 04:48
     
     
    My question is related to the inclusion of drop-down list in a web grid in MVC 3.0.

    My Controller Written data as:

     

         var query = ezee.Select(c => new SelectListItem
                    {
                        Value = c.CUSTOMLISTId.ToString(),
                        Text = c.CUSTOMLISTName.ToString(),
                        Selected = c.CUSTOMLISTId.Equals(itemlist.Select(i=>i.RESOURCETYPEID))
                    });
        
                    ViewBag.CUSTOMLIST= query.AsEnumerable();
        

    i have added a drop down control to my webgrid like that :

        gridcolumns.Add(grid.Column(header: "", format: @item => Html.DropDownList("COLUMN NAME", (IEnumerable<SelectListItem>)ViewBag.CUSTOMLIST)));

    The above works fine as "viewbag.CUSTOMLIST" brings me all the data from controller which i want to display, now my problem is how i can show the "selected" item in the drop down in web grid's row. I am trying to do this :

         gridcolumns.Add(grid.Column(header: "", format: @item => @Html.DropDownListFor("COLUMN NAME", ((IEnumerable<SelectlistItem>)ViewBag.CUSTOMLIST).Select(option => new SelectListItem
                     {
                         Text = (option == null ? "None" : option.Name),
                         Value = option.Id.ToString(),
                         Selected = (Model != null) && (option.Id == Model.Id)
                     }), "----Select Group----", "Group")));

    By using the above my problem will get solved but this is giving me an error as :

    "cannot convert from lambda expression to system.func<dynamic,object>"
    as inside the grid LINQ or LAMBDA is not permitted.

    WHAT should i do to show the selected item in drop down against particular records in web grid ???

    Any help will be of great deal....
    Thanks in Advance....