小怪兽爱吃肉
用GridView自带的删除、修改就应该在GridView事件里写 --前台这样写<asp:GridView ID="GridView1" runat="server" Width="70%" AutoGenerateColumns="False" Font-Size="Small" OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="15"> <Columns> <asp:BoundField DataField="Number" HeaderText="列名1" /> <asp:BoundField DataField="BedNumber" HeaderText="列名2" /> <asp:BoundField DataField="Description" HeaderText="列名3" /> <asp:BoundField DataField="StateName" HeaderText="列名4" /> <asp:BoundField DataField="GuestNumber" HeaderText="列名5" /> <asp:BoundField DataField="TypeName" HeaderText="列名6" /> <asp:TemplateField HeaderText="修改"> <ItemTemplate> <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="image/edit.gif" CommandName="Ed" CommandArgument=<%#Eval("标识列") %>> </asp:ImageButton> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="删除"> <ItemTemplate> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="image/delete.gif" CommandName="De" CommandArgument=<%#Eval("标识列") %>> </asp:ImageButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView --后台这样: 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 }