ASP.NET 中如何實現刪除、修改這些功能???
1 回答

小怪獸愛吃肉
TA貢獻1852條經驗 獲得超1個贊
用GridView自帶的刪除、修改就應該在GridView事件里寫
? ??--前臺這樣寫
< asp:GridView ?ID = "GridView1" ?runat = "server" ?Width = "70%" ?AutoGenerateColumns = "False" ?
|
? ?
? --后臺這樣: ?protected ?void ?GridView1_RowDataBound( object ?sender,?GridViewRowEventArgs?e) ??? { ??????? int ?i; ??????? //執行循環,保證每條數據都可以更新 ??????? for ?(i?=?0;?i?<?GridView1.Rows.Count;?i++) ??????? { ??????????? //首先判斷是否是數據行 ??????????? if ?(e.Row.RowType?==?DataControlRowType.DataRow) ??????????? { ?????????????? ImageButton?imgbtn?=?(ImageButton)e.Row.FindControl( "ImageButton1" ); ??????????????? imgbtn.Attributes.Add( "onclick" , "return?confirm('您確認要刪除嗎?');" ); ???????????? } ??????? } ??? } ?protected ?void ?GridView1_RowCommand( object ?sender,?GridViewCommandEventArgs?e) ??? { ??????? string ?cmd?=?e.CommandName; ??????? int ?Id?=?Convert.ToInt32(e.CommandArgument); ??????? if ?(cmd?==? "De" ) ??????? { ??????????? //這是調用的刪除方法,根據標識列 ??????????? RoomManager.DeleteRoomByRoomId(Id); ??????? } ??????? else ?if (cmd== "Ed" ) ??????? {??????????? ??????????? //這是跳轉到其他頁面修改 ??????????? Page.Server.Transfer( "UpdateRooms.aspx?RoomId=" ?+?Id.ToString()); ??????? } ??????? binddate(); //重新綁定GridView ??? } |
? ??? ?
- 1 回答
- 0 關注
- 783 瀏覽
添加回答
舉報
0/150
提交
取消