zoukankan      html  css  js  c++  java
  • GridView 删除数据

    第一种直接在前台删除按钮上写代码

     <asp:TemplateField HeaderText="操作" ShowHeader="False">
                 <EditItemTemplate>
                     <asp:LinkButton ID="lBtnUpdate" runat="server" CausesValidation="True"
                         CommandName="Update" Text="更新"></asp:LinkButton>
                     &nbsp;<asp:LinkButton ID="LBtnCancel" runat="server" CausesValidation="False"
                         CommandName="Cancel" Text="取消"></asp:LinkButton>
                 </EditItemTemplate>
                 <ItemTemplate>
                     <asp:LinkButton ID="LBtnEdit" runat="server" CausesValidation="False"
                         CommandName="Edit" Text="编辑"></asp:LinkButton>
                     &nbsp;<asp:LinkButton ID="LBtnDelete" runat="server" CausesValidation="False"
                         CommandName="Delete" Text="删除"  OnClientClick="return confirm('是否删除当前行?');"></asp:LinkButton>
                 </ItemTemplate>
     </asp:TemplateField>

    第二种方法就是在后台GridView的RowDataBound方法中写入

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {

        //为按钮写入onlick方法都有几种写法,都是大同小异。
                方法一:LinkButton deleteBtn = (LinkButton)e.Row.FindControl("LBtnDelete");

           if (deleteBtn != null)
                  {
                    deleteBtn.Attributes.Add("onclick", "return confirm('请确定要删除所选的数据项吗?');");
                  }

        方法二:((LinkButton)e.Row.Cells[4].Controls[3]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[0].Text + "\"吗?')");

        方法三:((LinkButton)e.Row.Cells[4].FindControl("LBtnDelete")).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[0].Text + "\"吗?')");

            }

  • 相关阅读:
    ubuntu /etc/rc.local 不执行
    HTML中设置页面内嵌跳转
    JS使用AudioContext播放音乐
    Unity实现摄像机以某个物体为中心旋转
    Unity中实现通过鼠标对物体进行旋转平移缩放
    解决Windows上无法创建以点开头的文件问题
    解决FBX模型导入Unity后没有贴图的问题
    nedb中使用update更新数据的原理
    Electron 渲染进程中解决require is not defined的问题
    Base64转Blob的方式
  • 原文地址:https://www.cnblogs.com/linb/p/2858634.html
Copyright © 2011-2022 走看看