當我點擊刪除按鈕時,它不會調用刪除功能。誰能幫我?Gridview刪除行
protected void GridViewQuestion_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton lb = (ImageButton)e.Row.FindControl("ImageButtonDelete");
lb.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete this record " +
DataBinder.Eval(e.Row.DataItem, "question") + "')");
}
}
protected void GridViewQuestion_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int questionID = (int)GridViewQuestion.DataKeys[e.RowIndex].Value;
TopicEntity.deleteQuestion(questionID);
BindGridData();
}
public bool deleteQuestion(int QuestionID)
{
SqlConnection dbConnection = new SqlConnection(connectionString);
SqlCommand dbCommand = new SqlCommand();
dbCommand.CommandText = "DELETE FROM Question [email protected]";
dbCommand.Connection = dbConnection;
dbCommand.Parameters.AddWithValue("@QuestionID", QuestionID);
bool deleteSuccess = false;
try
{
dbConnection.Open();
dbCommand.ExecuteNonQuery();
deleteSuccess = true;
}
catch (Exception e)
{
throw e;
}
finally
{
dbConnection.Close();
}
return deleteSuccess;
}
我已經在我的GridView寫這些。當我點擊刪除按鈕有提示消息框。但它並沒有從數據庫中刪除。 – lixi 2012-02-16 18:42:27
@lixi好的,你的事件處理程序實際上已經達到了。你的問題聽起來像你的事件沒有發生。至於從你的數據庫中刪除數據,你需要發佈你的'deleteQuestion()'方法的代碼。沒辦法告訴那裏發生了什麼。 – 2012-02-16 18:45:04
@lixi請編輯您的問題併發布該代碼。 – 2012-02-16 18:47:02