Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > Grid > DropDownList inside grid Cloumn

Answered DropDownList inside grid Cloumn

Feed from this thread
  • Ganesh avatar

    Posted on Jan 31, 2011 (permalink)

    Hello,
        I need to bring add, update functionalities inside grid and grid contains two drop down list boxes. am able to bring DDL inside grid but when on update or insert its not routing DDL selected item value to controller. my implementation goes like this
    Model:
    -----------------

    public class Admin
    {
    [DataType(DataType.Text),Required]
    [DisplayName("Login ID")]
    public string LoginID { get; set; }

    [UIHint("Role")]
    [DisplayName("User Role")]
    public Role Role { get; set; }
    [UIHint("Company")]

    [DisplayName("Company Name")]
    public Company Company { get; set; }

    [DisplayName("IsActive")]
    public bool IsActive { get; set; }
    }

    code to populate role:
    --------------------
    ViewData["role"] = objListRole.Select(e => new { RoleID = e.RoleID, RoleName = e.RoleName });
    ViewData["company"] = objListCompany.Select(e=> new {CompanyID = e.CompanyID , CompanyName = e.CompanyName});

     

     

     

    MarkUp:
    ------------
      <%= Html.Telerik().Grid(Model)
                .Name("Grid")
                      .DataKeys(keys => keys.Add(c => c.LoginID))
                .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0", title = "Add New User" }))
                .DataBinding(dataBinding => dataBinding.Server()
            .Select("Selection", "AdminUser")
            .Insert("InsertUser", "AdminUser", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
            .Update("Save", "AdminUser", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
            .Delete("Delete", "AdminUser", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText }))
               .Columns(columns =>
                {
                    columns.Bound(c => c.LoginID).Title("Login ID");
                    columns.Bound(c => c.Role).Title("User Role");
                    columns.Bound(c => c.Company).Title("Company Name");
                    columns.Bound(c => c.IsActive).Title("IsActive");
                    columns.Bound(c => c.LoginID).Title("").Format(Html.ActionLink("Generate Password", "ResetPassword", new { id = "{0}" }).ToHtmlString()).Encoded(false).Width(150).ReadOnly(true);
                    columns.Command(commands =>
                    {
                        commands.Edit().ButtonType(GridButtonType.ImageAndText);
                        commands.Delete().ButtonType(GridButtonType.ImageAndText);
                    }).HtmlAttributes(new { style = "white-space:nowrap !important;" }).Width(200).Title("");
                   
                })
             .Editable(editing => editing.Mode(GridEditMode.InLine))
             .Selectable()
            .Footer(true)
     %>

    DDL MarkUp: (Similrly for Roles to populate mark up is there in folder display template and edit template)
    -------------------
    <%= Html.Telerik().DropDownList()
    .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
    .BindTo(new SelectList((IEnumerable)ViewData["company"], "CompanyID", "CompanyName", Model == null ? "" : Model.CompanyID.ToString()))
    %>

    Code Called when click on update button:

     

    public

     

     

    ActionResult Save(string id,int? roleId,int? comp)

    Here roleId and Comp are always null.

    Please help. its very urgent.

    Thanks in advance,
    Ganesh N

     

    Reply

  • Answer Georgi Krustev Georgi Krustev admin's avatar

    Posted on Jan 31, 2011 (permalink)

    Hello Ganesh,

     
    Arguments of the Save Action method should be same as the value of the name attibutes of the inputs which post data to the server. In other words if the input HTML element has name equal to name="Company", than Action method should accept int Company:

    [HTML]:

    <input name="Company" value="1" />

    [C#]:
    public ActionResult Save(int Company)
    {
        ...
    }

    You will need to check what is the name attributes of the rendered DDL components and name arguments of the Save Action in the same way.

    This requirement comes from ASP.NET MVC framework.

    Regards,
    Georgi Krustev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Ganesh avatar

    Posted on Jan 31, 2011 (permalink)

    Hello Georgi,

    Thank you very much, its working. I appreciate your timely response. Thank you once again

    Thanks,
    Ganesh N

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > Grid > DropDownList inside grid Cloumn
Related resources for "DropDownList inside grid Cloumn"

ASP.NET MVC Grid Features  |  Documentation  |  Demos  |  Telerik TV ]