我在 c# 中构建了一个基础设施 webdatagrid:
var columnOne = new BoundDataField();
columnOne.DataFieldName = "ColumnOne";
columnOne.Key = "columnOne";
columnOne.Header.Text = "columnOne";
var columnTwo = new BoundDataField();
columnTwo.DataFieldName = "ColumnTwo";
columnTwo.Key = "columnTwo";
columnTwo.Header.Text = "columnTwo";
WebDataGridObject.DataKeyFields = "ColumnOne";
WebDataGridObject.Columns.Add(columnOne);
WebDataGridObject.Columns.Add(columnTwo);
当从第一列的单元格中输入内容时,我想从 javascript 更新第二列的单元格。
例如,我的用户开始在第 3 行和第 1 列的单元格中输入一个值,第 2 行和第 2 行的单元格必须使用常量值自动更新,例如“更新”。
为此,我有点挣扎,我从我的 c# 中附加了很多客户端事件,我认为一个有用的是 keydown :
WebDataGridObject.ClientEvents.MouseDown = "WebDataGridView_MouseDown";
WebDataGridObject.ClientEvents.KeyDown = "WebDataGridView_KeyDown";
WebDataGridObject.Behaviors.EditingCore.Behaviors.CellEditing.CellEditingClientEvents.EnteredEditMode = "enteredEditMode";
WebDataGridObject.Behaviors.EditingCore.Behaviors.CellEditing.CellEditingClientEvents.ExitedEditMode = "exitedEditMode";
我想要我的 js keydown 事件处理程序,获取当前编辑的单元格的列键,如果它等于“columnOne”,则更新同一行和第二列的单元格的值。这是我的 js:
function WebDataGridView_KeyDown(webDataGrid, evntArgs) {
}
function WebDataGridView_MouseDown(webDataGrid, evntArgs) {
// this is where I am trying to get the column key of the currently edited cell
webDataGrid.get_behaviors().get_selection().get_selectedRowsResolved() [0].get_cell(3).get_text()
}
var gridRef;
var cellRef;
function enteredEditMode(grid, args) {
gridRef = grid;
cellRef = args.getCell();
if (cellRef._column._key === "headerName") {
alert('toto');
}
}
function exitedEditMode(grid, args) {
gridRef = null;
cellRef = null;
}