Articles in this section
Category / Section

How to set dropdown edit type for the .NET MVC TreeGrid column?

1 min read

It is possible to set the edit type as dropdown for TreeGrid column. We can also customize the data inside drop down with or without checkbox. So that we can choose single or multiple options from the dropdown box. Please find the below code snippet to set dropdown edit type for the TreeGrid column.

CSHTML

@(Html.EJ().TreeGrid("TreeGridContainer")
//…
.Columns(co =>
               {
//…
co.Field("Resource").HeaderText("Resource").EditType(TreeGridEditingType.Dropdown).DropDownData((IEnumerable<object>)ViewBag.resource).Add();
               }
             )
)

C#

public ActionResult Index()
        {
            var DataSource = TreeGridDefaultData.GetData();
            ViewBag.datasource = DataSource;
            ResourceList resource = new ResourceList();
            ViewBag.resource = resource.GetResources();           
            return View();
        }
 
        public class Resource
        {
            public int id { get; set; }
            public string text { get; set; }
            public string value { get; set; }
        }
 
        public class ResourceList
        {
            public List<Resource> GetResources()
            {
                List<Resource> ResourceCollection = new List<Resource>();
                ResourceCollection.Add(new Resource() { id = 1, text = "Project Manager", value = "Project Manager" });
                ResourceCollection.Add(new Resource() { id = 2, text = "Software Analyst", value = "Software Analyst" });
                //…
            }
        }

A sample to define and enable the dropdown data in TreeGrid is available in the following link.

Sample

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied