呵呵,這首先要感謝徐了,她給了我一些重要的提示。
以前學習時曾經沒有遇到這樣的問題,就是刪除後gridview控件的信息不能自動更新,我是是過了好多種方法都不行。昨天上網看信息時,覺得應該在刪除前加個確認提示,就把confirm函數保存了一下。可是還是懶得用,就是因爲這樣,我總是刪除記錄後用alert給個提示,起不到更新gridview控件的作用。今天徐焱來了,順便請教了一下,她說白老師都是要求她刪除時有確認提示,讓我試試。我本來想應該有可能,alert只是提示作用。嘿嘿,一試果然成了。下面是我做的一段代碼。
protected void lbtdel_Click(object sender, EventArgs e)
{
sql = "delete from replys where id=" + ((LinkButton)sender).CommandArgument.Trim();
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "confirm", "if (window.confirm('是否要執行')){"+WarningGoNo(sql)+"}", true);
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "alert('刪除成功')", true);
}
public string WarningGoNo(string sql)
{
conn.ExecuteNonQuery(sql);
conn.closeconn();
ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "alert", "location='Admin_Feedback.aspx'", true);
return "nihao";
}