Want to populate other columns in the grid from a singel DropDownList using ViewData

2 posts, 1 answers
  1. Larry
    Larry avatar
    11 posts
    Member since:
    Jul 2014

    Posted 03 Sep 2014 Link to this post

    I have a grid that has multiple DropDownLists.   All of the DropDownLists are populated using the ViewData object.    In this case, I have a DropDownList that I would actually like it to populate multiple other columns in the Grid.    I am not sure how I can access the other information in the ViewData object.   So the Project_Key and the NameDesc columns in the model are for the dropdown.   But, the other columns Mgt_Unit_Key, Program_Key and Zone_Key are columns in the ViewData that I want to use to populate (default) other columns in the grid to.    How can I access these other columns in the ViewData and assign them to columns in the grid?

    Here is the basics of my controller:
        public ActionResult TimecardIndex()
                ViewData["Projects"] = this.projectservice.GetDropDownList();
                return View();

    The grid looks like:
        .Columns(c =>
            c.Command(command => { command.Destroy(); }).Width(120).Lockable(true).Locked(true);
            c.Bound(p => p.Task_Date).Width(120).Lockable(true).Locked(true).EditorTemplateName("IRISDate");
            c.ForeignKey(p => p.Activity_Key, (System.Collections.IEnumerable)ViewData["Activities"], "Activity_Key", "NameDesc").Width(350).Lockable(true);
            c.ForeignKey(p => p.Project_Key, (System.Collections.IEnumerable)ViewData["Projects"], "Project_Key", "NameDesc").Width(350);
            c.ForeignKey(p => p.ProjectSub_Key, (System.Collections.IEnumerable)ViewData["ProjectSubs"], "ProjectSub_Key", "NameDesc").EditorTemplateName("ProjectSub").Width(200);
            c.ForeignKey(p => p.Mgt_Unit_Key, (System.Collections.IEnumerable)ViewData["Mgt_Units"], "Mgt_Unit_Key", "NameDesc").Width(350);
            c.ForeignKey(p => p.Program_Key, (System.Collections.IEnumerable)ViewData["Programs"], "Program_Key", "NameDesc").Width(350);
            c.ForeignKey(p => p.Zone_Key, (System.Collections.IEnumerable)ViewData["Zones"], "Zone_Key", "NameDesc").Width(350);
            c.ForeignKey(p => p.Road_Key, (System.Collections.IEnumerable)ViewData["Roads"], "Road_Key", "FullRoadNumber").Width(200);

    The model for the ProjectDropDown returned by the GetDropDownList() is:
     public class ProjectDropDown
            public string Project_Key { get; set; }

            [Display(Name = "Name")]
            public string NameDesc { get; set; }

            [Display(Name = "Mgt. Unit")]
            public string Mgt_Unit_Key { get; set; }

            [Display(Name = "Program")]
            public string Program_Key { get; set; }

            [Display(Name = "Zone")]
            public string Zone_Key { get; set; }

            [Display(Name = "Road")]
            public string Road_Key { get; set; }

  2. Answer
    Alexander Popov
    Alexander Popov avatar
    1444 posts

    Posted 05 Sep 2014 Link to this post

    Hello Larry,

    I already addressed this query in the support ticket you opened, however I will post my reply here as well.

    This could be acheived by subscribing the data item's change event and modifying the values accordingly. For example: 
    <script type="text/javascript">
        function onEdit(e) {
            e.model.bind("change", function (evt) {
                this.set("MyField", newValue); //get the value of the first DropdDwnList and use it to update the rest of the fields

    Alexander Popov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top