小白求教:GridView删除的问题,高手帮忙啊!!
写的删除事件的代码如下,但点击删除按钮,却没有反应。当然,数据库里的数据也没有变。恳请高手指点。
protected void GridView1_OnRowDeleteCommand(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
strSql = "delete * from employees where emp_Id='" +id+ "'";
try
{
SqlConnection conn = DB.createSqlconnection();
if (conn.State.ToString() == "Closed")
{
conn.Open();
}
SqlCommand cmd = new SqlCommand(strSql, conn);
if (cmd.ExecuteNonQuery() > 0)
{
cmd.Dispose();
conn.Close();
Response.Write("<script>alert('删除成功!')</script>");
}
else
{
Response.Write("<script>alert('删除失败!')</script>");
}
GridView1.EditIndex = -1;//返回没有编辑的状态
this.Data_Bind("");
}
catch (Exception ex)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
Response.End();
}
}