GridView操作小技巧-自定义删除按钮

没事准备学Linq的,绑定GridView的时候,突然想自己定义操作的命令了,琢磨了半天还是没搞懂,后来参考别人的代码才知道~!自定义一个按钮~!呵呵
                 < asp:TemplateField HeaderText = " 删除操作 " >
                    
< ItemTemplate >
                        
< asp:Button Text = " 删除 "  runat = " server "  OnClientClick = " return confirm('确定要删除?') "  ID = " Button1 "  OnCommand = " Button1_Click "
                         CommandName
= " Button1_Click "  CommandArgument = ' <%#Eval("CustomerID") %> '   />
                    
</ ItemTemplate >
                
</ asp:TemplateField >
然后后台相应的要有代码:处理Button1_Click事件
         protected   void  Button1_Click( object  sender, CommandEventArgs e)
        
{
            Response.Write(
"按钮按了" + e.CommandArgument.ToString());
        }
可以看到绑定的Argument的值已经传了,呵呵,删除还是修改随便弄啦~!

你可能感兴趣的:(GridView)