【问题标题】:Add event handler to RadGrid programmatically以编程方式将事件处理程序添加到 RadGrid
【发布时间】:2026-02-02 08:10:01
【问题描述】:

我以编程方式创建了一个 RadGrid 并尝试将 BatchEditCommand 绑定到它,但它没有更新并在单击多个保存后消失。 BatchEditCommand 根本没有触发,不知道触发了什么事件,我很难调试,也许我在创建 RadGrid 时错过了一些重要的设置?

for (int i = 1; i <= 1; i++)
{
    strategy = strategy + Convert.ToString(i);
    RadGrid RadGrid_Strategy = new RadGrid();
    RadGrid_Strategy.ID = strategy;
    RadGrid_Strategy.Skin = "Office2010Blue";
    RadGrid_Strategy.GridLines = System.Web.UI.WebControls.GridLines.Both;
    RadGrid_Strategy.DataSource = GetDataTableForStrategy(CY, i);
    RadGrid_Strategy.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
    RadGrid_Strategy.ShowHeader = false;
    RadGrid_Strategy.BatchEditCommand += new GridBatchEditEventHandler(RadGrid_BatchEditCommand);
    RadGrid_Strategy.MasterTableView.EditMode = GridEditMode.Batch;
    RadGrid_Strategy.MasterTableView.BatchEditingSettings.EditType = GridBatchEditingType.Cell;
    RadGrid_Strategy.AllowAutomaticUpdates = true;
    RadGrid_Strategy.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
    RadGrid_Strategy.MasterTableView.CommandItemSettings.ShowSaveChangesButton = true;
    RadGrid_Strategy.MasterTableView.CommandItemSettings.ShowCancelChangesButton = true;
    PlaceHolder1.Controls.Add(RadGrid_Strategy);
    RadGrid_Strategy.Rebind();
}

BatchEditCommand 根本没有触发:

protected void RadGrid_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{...}

【问题讨论】:

    标签: c# telerik-grid radgrid


    【解决方案1】:

    您尝试调用的事件只有在您对网格进行更改时才会被触发,然后从 RadGrid 的 BatchEditingManager 调用这些客户端函数中的任何一个:

    • saveChanges(tableView)
    • saveAllChanges()
    • saveTableChanges(tableViews)

    查看 Telerik 论坛上的 this thread 了解更多信息。

    【讨论】: