为了账号安全,请及时绑定邮箱和手机立即绑定

ASP.NET 中如何实现删除、修改这些功能啊?

ASP.NET 中如何实现删除、修改这些功能啊?

倚天杖 2018-08-26 21:06:36
ASP.NET 中如何实现删除、修改这些功能啊? 
查看完整描述

1 回答

?
小怪兽爱吃肉

TA贡献1852条经验 获得超1个赞

用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   }

       


查看完整回答
反对 回复 2018-09-21
  • 1 回答
  • 0 关注
  • 747 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信