DeleteConfirm Grid删除行 提示确认删除

//GridView行数据绑定事件
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow) //如果是数据行
   {
      GridView grid = sender as GridView; //取当前操作的GridView
      //为GridView数据行的"删除方法1"按钮添加删除确认对话框
      ((LinkButton)(e.Row.Cells[grid.Columns.Count -1].Controls[0])).Attributes.Add("onclick", "return confirm('确认删除?');");
   }
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
   if (e.CommandName == "Del")
   {
      int index = Convert.ToInt32(e.CommandArgument); //取GridView行索引号
      GridView grid = (GridView)e.CommandSource; //取当前操作的GridView
      int id = Convert.ToInt32(grid.DataKeys[index].Value); //取GridView的主键值
      Response.Write("用户ID:" + id.ToString() + " 删除成功");

   }
}

你可能感兴趣的:(confirm)