注册 登录
编程论坛 ASP.NET技术论坛

请问为什么RowDeleteing成功删除了记录,但是不能触发RowDeleted事件呢?

hellenism 发布于 2010-05-28 18:14, 975 次点击
是RowDeleteing中没有设置主键的原因吗?
RowDeleteing能正确删除记录,但是之后页面没有弹出"删除成功"
 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        
            int index = e.RowIndex;//取得当前行号,并取得当前行的GridViewRow对象

            GridViewRow gvR = GridView1.Rows[index];

            //取得当前行第三个单元格中的文字

            string deleteItem = gvR.Cells[2].Text;


            string strCon = "Data Source=.;" +
                                   "Initial Catalog=studentManageSystem;" +
                                   "Integrated Security=True;";

            string strSQL = string.Format("delete from studentScoreInfo where Sno='{0}'", deleteItem);

            SqlConnection con = new SqlConnection(strCon);

            con.Open();

            SqlCommand cmd = new SqlCommand(strSQL, con);

            cmd.ExecuteNonQuery();
      
    }


protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
        if (e.Exception == null)
        {
            Response.Write("<script type='text/javascript'>alert('删除成功!')</script>");
            .......
           ..........
            .........

        }
        else
        {
            Response.Write("<script type='text/javascript'>alert('删除失败!')</script>");
        }
1 回复
#2
mijia2010-05-28 19:41
有这个con.Open();应该也要有这个吧close.Open()
1