<ej-drop-down-list id="selectCompany" datasource="ViewBag.data" change="drpvaluechange">
<e-drop-down-list-fields text="EmployeeID" value="EmployeeID" />
</ej-drop-down-list>
<ej-grid id="FlatGrid" datasource="(IEnumerable<object>)ViewBag.datasource" allow-paging="true" load="load" cell-edit="celledit" before-batch-save="beforeSave">
<e-columns>
<e-column field="OrderID" header-text="Order ID" is-primary-key="true" text-align="Right" width="75"></e-column>
<e-column field="EmployeeID" header-text="Employee ID" text-align="Right" width="75"></e-column>
<e-column field="CustomerID" header-text="Customer ID" width="80"></e-column>
<e-column field="Freight" header-text="Freight" format="{0:C}" text-align=Right width="75"></e-column>
<e-column field="ShipCity" header-text="Ship City" width="110" text-align="Left"></e-column>
</e-columns>
</ej-grid>
<script>
function drpvaluechange(args) {
$.ajax({
url: 'GetData',
type: 'Get',
data: { "ID": args.value },
success: (function (data) {
var gridObj = $(".e-grid").ejGrid("instance");
gridObj.dataSource(data);
})
});
}
</script>
|
HomeController.cs
public IActionResult Index()
{
DataTable dt = new DataTable("Student");
dt.Columns.Add("value", typeof(Int32));
dt.Columns.Add("text", typeof(string));
dt.Rows.Add(1, "MANISH");
dt.Rows.Add(2, "PASTA");
List<detail> studentList = new List<detail>();
for (int i = 0; i < dt.Rows.Count; i++)
{
detail customer = new detail();
customer.value = Convert.ToInt32(dt.Rows[i]["value"].ToString());
customer.text = dt.Rows[i]["text"].ToString();
studentList.Add(customer);
}
ViewBag.dataSource = OrdersDetails.GetAllRecords().ToList();
ViewBag.DropDownData = studentList.ToList() ;
return View();
} |
Index.cshtml
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" type="string" width="120" edit="@(new {create = "create", read = "read", destroy = "destroy", write = "write"})"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
<script>
var elem;
var dObj;
function create(args) {
elem = document.createElement('input');
return elem;
}
function destroy() {
dObj.destroy();
}
function read() {
return dObj.text;
}
function write(args) {
dObj = new ej.dropdowns.DropDownList({
dataSource: @Html.Raw(Json.Serialize(ViewBag.DropDownData)),
fields: { value: 'value', text: 'text' },
floatLabelType: 'Never'
})
dObj.appendTo(elem);
}
</script>
|
Detail.cs
internal string detailName;
public string text { get; internal set; }
public int value { get; internal set; }
}
} |
|