0
我以編程方式生成GridView
s,每個GridView
都有一個帶刪除按鈕的CommandField
。如何以編程方式添加OnDeletingRow
,以便在單擊GridView
的刪除按鈕時調用某個功能?以編程方式將OnRowDelete添加到GridView
GridView gv = new GridView();
gv.AutoGenerateColumns = false;
gv.ID = "GridView_" + selectedId;
gv.DataKeyNames = new string[] {"id"};
gv.AllowPaging = false;
gv.CellPadding = 3;
gv.RowDeleting += new GridViewDeleteEventHandler(gv_RowDeleting);
CommandField commandfieldDeallocate = new CommandField();
commandfieldDeallocate.HeaderText = "DELETE NUMBER";
commandfieldDeallocate.ShowDeleteButton = true;
commandfieldDeallocate.DeleteText = "DELETE";
gv.Columns.Add(commandfieldDeallocate);
ConnorsFan,感謝您的解決方案,但由於某種原因,該功能不被調用對我來說,任何想法?我已將我的代碼添加到原始問題中。 – Kate
解決方案可能在這篇文章中(幸運的是,答案比問題短得多):http://stackoverflow.com/questions/11336564/programatically-creating-gridview-but-postback-when-update-clicked-prevents -rowu – ConnorsFan