public class FeeScriptsController : Controller { public ActionResult Index() { List<FeeScriptModel> studentList = new List<FeeScriptModel>() { new FeeScriptModel(){ DescriptionValue=1 }, new FeeScriptModel(){ DescriptionValue=2 }, new FeeScriptModel(){ DescriptionValue=3 }, new FeeScriptModel(){ DescriptionValue=4 }, new FeeScriptModel(){ DescriptionValue=5 } }; List<dropDown> list = new List<dropDown>(); list.Add(new dropDown(3, 1)); list.Add(new dropDown(4, 2)); ViewBag.dataSource = studentList; ViewBag.dataSource2 = list; return View(); }
}
@(Html.EJ().Grid<FeeScriptModel>("FlatGrid") .Datasource((IEnumerable<FeeScriptModel>)ViewBag.dataSource) .AllowPaging() .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); }) .ToolbarSettings(toolbar => { toolbar.ShowToolbar().ToolbarItems(items => { items.AddTool(ToolBarItems.Add); items.AddTool(ToolBarItems.Edit); items.AddTool(ToolBarItems.Delete); items.AddTool(ToolBarItems.Update); items.AddTool(ToolBarItems.Cancel); }); }) .Columns(col => { col.Field("DescriptionValue") .HeaderText("Desc Value") .Add(); col.Field("DescriptionValue") .HeaderText("dropdown") .DataSource(ViewBag.dataSource2) .EditType(EditingType.DropdownEdit).Add(); }) )
Thank you.
[GridCOntroller.cs]
public class GridController : Controller
{
List<Employees> emp = new List<Employees>();
public ActionResult GridSample()
{
---
BindDataSource();
ViewBag.dropData = emp;
return View();
}
private void BindDataSource()
{
if (emp.Count == 0)
{
emp.Add(new Employees() { text = "Argentina", value = "Argentina" });
emp.Add(new Employees() { text = "Austria", value = "Austria" });
emp.Add(new Employees() { text = "Belgium", value = "Belgium" });
emp.Add(new Employees() { text = "Brazil", value = "Brazil" });
emp.Add(new Employees() { text = "Canada", value = "Canada" });
---
}
}
public class Employees
{
public string text { get; set; }
public string value { get; set; }
}
----------------------------------
[GridSample.cshtml]
@(Html.EJ().Grid<object>("FlatGrid")
.AllowPaging() /*Paging Enabled*/
----
.Columns(col =>
{
----
col.Field("ShipCountry").HeaderText("Ship Country").EditType(EditingType.Dropdown)
.DataSource((IEnumerable<object>)ViewBag.dropData).Width(110).Add();
}))
|
Hi,
I know how to populate data for the grid and the dropdown, but when in edit-mode, they are not mapped together. I attached a screenshot shown example.
Thank a lot.
[GridController.cs]
public class GridController : Controller
{
List<Employees> emp = new List<Employees>();
public ActionResult GridSample()
{
var DataSource = new NorthwindDataContext().OrdersViews.ToList();
ViewBag.datasource = DataSource; // dataSource for Grid
BindDataSource();
ViewBag.dropData = emp; // dataSource for dropdown column
return View();
}
private void BindDataSource() // creating dataSource for dropdown column
{
if (emp.Count == 0)
{
emp.Add(new Employees() { text = "Argentina", value = "Argentina" });
emp.Add(new Employees() { text = "Austria", value = "Austria" });
emp.Add(new Employees() { text = "Belgium", value = "Belgium" });
emp.Add(new Employees() { text = "Brazil", value = "Brazil" });
emp.Add(new Employees() { text = "Canada", value = "Canada" });
---
}
}
public class Employees
{
public string text { get; set; }
public string value { get; set; }
}
----------------------------------
[GridSample.cshtml]
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource) // binding dataSource for Grid
.AllowPaging() /*Paging Enabled*/
----
.Columns(col =>
{
----
col.Field("ShipCountry").HeaderText("Ship Country").EditType(EditingType.Dropdown)
.DataSource((IEnumerable<object>)ViewBag.dropData).Width(110).Add(); // bind those text and value pair data to the dropdown column
}))
|