[ASP.NET][GridView] RowDeleting事件

  • 1533
  • 0

做個筆記~

GridView 的 RowDeleting事件

 

protected void GridView1_Rowdeleting(object sender, GridViewDeleteEventArgs e)
{
  string RecNo = GrdView1.DataKeys[e.RowIndex].Value.ToString();   //GridView的DataKeyNames為RecNo
  conn.Open();
  SqlCommand cmd = new SqlCommand("Delete From Table WHERE RecNo= @RecNo", conn);
  cmd .Parameters.AddWithValue("@RecNo",RecNo);
  cmd.ExecuteNonQuery();
  MAconn.Close();
 
  this.SelectDatabind();//重新載入資料
}