GridView提示删除完整代码

 
GridView提示删除完整代码

来自http://bombgod.bokee.com/5628974.html

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        foreach (TableCell tc in e.Row.Cells)
        {
            if (tc.Controls.Count>0)
            {
                foreach (Control con in tc.Controls)
                {
                    if (con.GetType().ToString() == "System.Web.UI.WebControls.DataControlLinkButton")
                    {
                        LinkButton lb = (LinkButton)con;
                        if (lb.CommandName=="Delete")
                        {
                            lb.Attributes.Add("onclick", "return confirm('您真的要删除这个用户吗?')");
                        }
                    }
                }
            }
        }
    }

 

来自http://www.supengcast.net/default.aspx

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //在服务器端添加删除确认
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
             LinkButton btnDelete = (LinkButton)e.Row.FindControl("LinkButton1");
             btnDelete.Attributes.Add("onclick", "javascript:return " +"confirm('Are you sure you want to delete this record " +DataBinder.Eval(e.Row.DataItem, "编号") + "')");
        }
     }

你可能感兴趣的:(GridView提示删除完整代码)