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

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

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

HUX布斯 2018-10-29 00:00:56
ASP.NET 中如何实现删除、修改这些功能啊?
查看完整描述

1 回答

?
森栏

TA贡献1810条经验 获得超5个赞


用GridView自带的删除、修改就应该在GridView事件里写

    --前台这样写

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

<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

   

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

 --后台这样:

 

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-11-15
  • 1 回答
  • 0 关注
  • 350 浏览

添加回答

举报

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