第一删除按钮 我使用的是 <asp:CommandField ButtonType="Button" ShowDeleteButton="True" />
当第一次删除时会(当选择“编辑”以后再删就不会出现错误)错误提示 :索引超出范围。必须为非负值并小于集合大小。(注:编辑按钮 同意是这样但是却能很好的运行)第二 我想提示删除对话框 方法中第一句没有起作用(再dateBind事件中加入 e.Row.Cells[8].Attributes.Add("onclick", "return confirm('确定删除吗?');")依然没用),如何用别的方法第三 当加了第一句删除提示时,最后一句删除成功的信息就不会显示了,为何? 不加第一句,最后一句可以正常显示protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//Response.Write("<script> confirm('do you want to delete it!') </script");
int index = e.RowIndex;
string stdID = GridView1.DataKeys[index].Value.ToString();
string strSql = "delete TbSalary where 学号='" + stdID + "'";
SqlConnection conn = new SqlConnection(@"Data Source=LIU\SQLEXPRESS;Initial Catalog=QGZXT;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand(strSql, conn);
cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();
Response.Write("<script> alert(' you have deleted it!') </script");
}
当第一次删除时会(当选择“编辑”以后再删就不会出现错误)错误提示 :索引超出范围。必须为非负值并小于集合大小。(注:编辑按钮 同意是这样但是却能很好的运行)第二 我想提示删除对话框 方法中第一句没有起作用(再dateBind事件中加入 e.Row.Cells[8].Attributes.Add("onclick", "return confirm('确定删除吗?');")依然没用),如何用别的方法第三 当加了第一句删除提示时,最后一句删除成功的信息就不会显示了,为何? 不加第一句,最后一句可以正常显示protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//Response.Write("<script> confirm('do you want to delete it!') </script");
int index = e.RowIndex;
string stdID = GridView1.DataKeys[index].Value.ToString();
string strSql = "delete TbSalary where 学号='" + stdID + "'";
SqlConnection conn = new SqlConnection(@"Data Source=LIU\SQLEXPRESS;Initial Catalog=QGZXT;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand(strSql, conn);
cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();
Response.Write("<script> alert(' you have deleted it!') </script");
}
function deleteclick()
{
if(confirm('do you want to delete it!'))
return true;
else
{
event.returnValue = false;
return false;
}
}然后把CS代码里的去掉