| ... <ejs-grid id="Grid" allowSorting="true" toolbar="@(new List<string>() { "Add", "Update", "Cancel" })" allowPaging="true"> <e-data-manager url="/Home/UrlDatasource/" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Delete" adaptor="UrlAdaptor" crossdomain="true"></e-data-manager> ... <e-grid-columns> ... <e-grid-column field="ShipCountry" headerText="Ship Country" width="150" editType = "dropdownedit" edit = "@(new { @params = new { dataSource = ViewBag.DropDown , fields= new { text = "ShipCountry", value ="ShipCountry"} }})" ></e-grid-column> ... </e-grid-columns> </ejs-grid> </div> |
| ... public IActionResult Index() { var shipcountry = data.GetAllRecords(); ViewBag.DropDown = shipcountry; return View(); } ... public class data //Creating datasource for dropdownedit { public static List<data> ship = new List<data>(); public data() { } public data(string ShipCountry) { this.ShipCountry = ShipCountry; } public static List<data> GetAllRecords() { if (ship.Count() == 0) { ship.Add(new data("ALFKI")); ship.Add(new data("ANATR")); ship.Add(new data("ANTON")); ship.Add(new data("BLONP")); ship.Add(new data( "BOLID")); } return ship; } public string ShipCountry { get; set; } } } ... |
| ... public IActionResult Index() { ... var enumData = Enum.GetValues(typeof(OrderList)).Cast<Enum>().Select(value => new { (Attribute.GetCustomAttribute(value.GetType().GetField(value.ToString()), typeof(DescriptionAttribute)) as DescriptionAttribute).Description, value }).OrderBy(item => item.value).ToList(); ViewBag.DropDown1 = enumData; ... } public enum OrderList { [Description("ALFKI")] order1 = 1, [Description("ANATR")] order2 = 2, [Description("ANTON")] order3 = 3, [Description("BLONP")] order4 = 4, [Description("BOLID")] order5 = 5 } … [.cshtml] ... <e-grid-column field="ShipCountry" headerText="Ship Country" width="150" editType="dropdownedit" edit="@(new { @params = new { dataSource = ViewBag.DropDown, Query = "new ej.data.Query()", fields= new { text= "ShipCountry", value ="ShipCountry" } } })" ></e-grid-column> ... |