以前,当我的RadGrid不是批量编辑网格时,我能够使用网格的AddNewRecord按钮将用户重定向到另一个页面,使用以下代码:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "InitInsert")
{
Response.Redirect(redirectUrl + "?ProductID=" + this.ProductId);
}
}
在我使我的网格批量编辑网格后,添加新按钮不再进入ItemCommand事件,而是尝试向网格添加内联插入记录行。无论如何,我仍然可以使用这个按钮,并覆盖其功能,仍然重定向用户?
所以我已经测试了这个,并证实了我在评论中的怀疑。当EditMode="Batch"
时,"添加新记录"按钮,连同其他按钮,不再引起回发。您可以通过在RadGrid1_ItemCreated
中删除OnClientClick
的JavaScript来覆盖它,如下所示:
将此添加到您的RadGrid1
属性:
OnItemCreated="RadGrid1_ItemCreated"
后面的代码(注意:实际上有一个Button
和一个LinkButton
):
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item.ItemType == Telerik.Web.UI.GridItemType.CommandItem) {
//This is the icon with the plus (+) sign unless you've changed the icon
Button iconButton = e.Item.FindControl("AddNewRecordButton");
if (iconButton != null) {
iconButton.OnClientClick = "";
}
//This is the words "Add New Record" or whatever you've called it
LinkButton wordButton = e.Item.FindControl("InitInsertButton");
if (wordButton != null) {
wordButton.OnClientClick = "";
}
}
}
这应该允许回发发生,你发布的代码应该能够运行。