You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET WebForms模态框中Telerik RadGrid的OnBatchEditCommand取值异常

解决ASP.NET WebForms中Telerik RadGrid前端绑定数据后BatchEditCommand无法取值的问题

在ASP.NET WebForms的模态框中使用Telerik RadGrid,通过jQuery调用set_dataSource和dataBind绑定数据后,后台OnBatchEditCommand事件里无法获取OldValues和NewValues的内容。

前端绑定代码

var tableView = $find("<%= RadGrid2.ClientID %>").get_masterTableView();
tableView.set_dataSource(data);
tableView.dataBind();

后台事件代码

protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
    foreach (GridBatchEditingCommand command in e.Commands)
    {
        Hashtable oldValues = command.OldValues;
        Hashtable newValues = command.NewValues;
        // 此处oldValues和newValues为空或无有效数据
    }
}

问题原因及解决办法

  1. 控件ID不匹配:先检查前端代码里的RadGrid ID是RadGrid2,但后台事件绑定的是RadGrid1_BatchEditCommand,这大概率是笔误,必须确保控件ID和事件绑定的目标完全一致。

  2. 前端绑定未触发批处理追踪:Telerik RadGrid的批处理机制需要主动追踪数据初始状态,纯前端直接绑定的数据不会被框架自动纳入追踪体系,需要手动触发状态同步:

    var tableView = $find("<%= RadGrid2.ClientID %>").get_masterTableView();
    tableView.set_dataSource(data);
    tableView.dataBind();
    // 让批处理管理器识别并追踪当前数据状态
    tableView.get_batchEditingManager().trackChanges();
    
  3. 改用官方推荐的绑定模式:如果业务场景允许,优先使用RadGrid的客户端绑定模式(配置DataSourceID或后台绑定后前端调用rebind()刷新),这种模式下框架会自动维护数据状态,批处理事件能正常获取新旧值。

  4. 检查BatchEditing配置:确保RadGrid的BatchEditingSettings已正确开启(如设置EditType="Batch"),同时确认所有需要编辑的列都配置了UniqueName属性——这是框架识别字段、维护数据映射的关键。

内容的提问来源于stack exchange,提问作者Ahsan J. Khan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 09:45:45