How to change the dropdown data source while editing? We can change the Dropdown data source while editing the Grid instead of default data source. This can be achieved by using actionComplete event in Grid. The following code example demonstrates how to change the dropdown data source while editing.
JS
MVC
ASP
actionComplete event
The following screenshot display the new Dropdown data source while editing the Grid. Figure 1: Output |
This page will automatically be redirected to the sign-in page in 10 seconds.
This gets me 90% of the way there but then you use "
$("
#GridEmployeeID")
". Where does GridEmployeeID come from? Is this something that Syncfusion creates? If so then how are we supposed to know what the drop-down-list will be named?Hi William,
"
$("
#GridEmployeeID")
". is the id dropdown element which is the combination of Grid id and column field name.Regards,
Alan Sangeeth S
Hello Alan,
I tried the below code in my Razor view and i am unable to see the Dropdown values for the cloumn in the grid. can you please suggest any change to make it work.
<div id="ControlRegion">
<br />
<div>
<table style="padding-left: 200px">
<tr>
<td style="width:auto">
@(Html.EJ().Grid<UnitClassPlanTool.Models.DeptPlanLevel>("FlatGrid")
.Datasource((IEnumerable<UnitClassPlanTool.Models.DeptPlanLevel>)ViewBag.deptplans)
.EditSettings(edit => { edit.AllowEditing(); })
.ClientSideEvents(eve=>eve.ActionComplete("actionComplete"))
.Columns(col =>
{
col.Width("150px").Field("DeptID").HeaderText("Department").HeaderTextAlign(TextAlign.Center).IsPrimaryKey(true).Add();
col.Width("275px").Field("PlanLevelName").HeaderText("Plan Level").HeaderTextAlign(TextAlign.Center).EditType(EditingType.Dropdown).Add();
}))
</td>
</tr>
</table>
</div>
</div>
<script type="text/javascript">
function actionComplete(args) {
//while editing the grid
if (args.requestType == "beginedit") {
//New Dropdown data source and here text is display purpose and values is saved to data base.
var dpDataSource = [{ value: 1, text: 'WOS' }, { value: 2, text: 'TopDown' }, ];
$("#GridPlanLevelName").ejDropDownList({ dataSource: dpDataSource, selectedIndex: 1 }); //Set the new Dropdown datasource
}
}
</script>
I am not sure why the HTML tags lost. here is the scriptblock i used
<script type="text/javascript">
function actionComplete(args) {
//while editing the grid
if (args.requestType == "beginedit") {
//New Dropdown data source and here text is display purpose and values is saved to data base.
var dpDataSource = [{ value: 1, text: 'WOS' }, { value: 2, text: 'TopDown' }, ];
$("#GridPlanLevelName").ejDropDownList({ dataSource: dpDataSource, selectedIndex: 1 }); //Set the new Dropdown datasource
}
}
</script>
function actionComplete(args) {
//while editing the grid
if (args.requestType == "beginedit") {
//New Dropdown data source and here text is display purpose and values is saved to data base.
var dpDataSource = [{ value: 1, text: 'WOS' }, { value: 2, text: 'TopDown' }, ];
$("#GridPlanLevelName").ejDropDownList({ dataSource: dpDataSource, selectedIndex: 1 }); //Set the new Dropdown datasource
}
}