ASP.NET 中如何實現(xiàn)刪除、修改這些功能?。?nbsp;
1 回答

小怪獸愛吃肉
TA貢獻1852條經(jīng)驗 獲得超1個贊
用GridView自帶的刪除、修改就應(yīng)該在GridView事件里寫
? ??--前臺這樣寫
< asp:GridView ?ID = "GridView1" ?runat = "server" ?Width = "70%" ?AutoGenerateColumns = "False" ?
|
? ?
? --后臺這樣: ?protected ?void ?GridView1_RowDataBound( object ?sender,?GridViewRowEventArgs?e) ??? { ??????? int ?i; ??????? //執(zhí)行循環(huán),保證每條數(shù)據(jù)都可以更新 ??????? for ?(i?=?0;?i?<?GridView1.Rows.Count;?i++) ??????? { ??????????? //首先判斷是否是數(shù)據(jù)行 ??????????? 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" ) ??????? { ??????????? //這是調(diào)用的刪除方法,根據(jù)標識列 ??????????? RoomManager.DeleteRoomByRoomId(Id); ??????? } ??????? else ?if (cmd== "Ed" ) ??????? {??????????? ??????????? //這是跳轉(zhuǎn)到其他頁面修改 ??????????? Page.Server.Transfer( "UpdateRooms.aspx?RoomId=" ?+?Id.ToString()); ??????? } ??????? binddate(); //重新綁定GridView ??? } |
? ??? ?
- 1 回答
- 0 關(guān)注
- 787 瀏覽