GridView删除时提示 是否删除

GridView删除时提示 是否删除
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                            AutoGenerateColumns="False" DataKeyNames="iDeptID" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" >


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
         LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");

           //string a= e.Row.Cells[1].Text; //第二列的值

         //    e.Row.Cells[6].Attributes.Add("onclick", "return confirm('" + a + "');"); //7列是删除按钮,也可以这样给出提示


            if (l.Text == "删除")      //取消时不提示
             {
                 string title = "是否要删除该记录?" + DataBinder.Eval(e.Row.DataItem, "sDeptName");
                 l.Attributes.Add("onclick", "javascript:return " + "confirm('" + title + "')");
             }

         }
        }

2.简单的删除提示:OnClientClick="return confirm('确认要删除此行信息吗?');"

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
                               Text="删除" OnClientClick="return confirm('确认要删除此行信息吗?');"></asp:LinkButton>

你可能感兴趣的:(GridView)