public IActionResult Index()
{
String strConnString = ConfigurationManager.ConnectionStrings["NORTHWNDConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Shipping";
cmd.Connection = con;
con.Open();
List<object> dropObj = new List<object>();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
//Convert them to text/value pair
dropObj.Add(new { text = dr.GetValue(0).ToString(), value = dr.GetValue(0).ToString() });
}
}
con.Close();
ViewBag.dropObj = dropObj;
ViewBag.GridData = new NorthwindDataContext().OrdersViews.ToList();
return View();
}
@{Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.GridData)
.AllowPaging()
.Columns(col =>
{
.. .
.. .
//Dropdown column
col.Field("ShipCountry").HeaderText("Ship Country")
.DataSource((IEnumerable<object>)ViewBag.dropObj)
.EditType(EditingType.Dropdown).Add();
}).Render();
} |
@{Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.GridData)
.AllowPaging()
.Columns(col =>
{
.. .
. . .
//ForeignKey column
col.Field("EmployeeID").HeaderText("Employee Name")
.ForeignKeyField("EmployeeID")
.ForeignKeyValue("FirstName")
.DataSource((IEnumerable<object>)ViewBag.forObj)
.TextAlign(TextAlign.Left).Add();
}).Render();
}
|