[英]Gridview is updated with SqlCommand but then edit and delete are no longer working
[英]gridview With delete action .column needs to be updated
我有一個帶刪除動作的gridview ..特定行需要對其進行更新。 這樣做時出現錯誤。
無效的回發或回調參數。 使用配置或頁面中的<%@頁面EnableEventValidation =“ true”%>啟用事件驗證。 為了安全起見,此功能驗證回發或回調事件的參數源自最初呈現它們的服務器控件。 如果數據有效且預期,請使用ClientScriptManager.RegisterForEventValidation方法以注冊回發或回調數據以進行驗證。
如何為gridview編寫客戶端事件。
我的GridView
請告訴我如何糾正此錯誤。.要求是單擊“刪除”按鈕,該行需要更新為特定的設置值。
您對AddWithValue方法的調用錯誤。 當應該使用AddWithValue隱式地指定SqlDbType時:
string yourId = "1";
con.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Id", yourId);
另外,我看不到應該將Id值作為參數傳遞的位置。 我添加了yourId變量,因為沒有id值。
如果要指定類型,請不要使用AddWithValue,而要使用Add,而是:
string yourId = "1";
con.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@Id", SqlDbType.NVarChar).Value = yourId;
另外,您確定ID列應為NVarChar嗎?
private void Page_Load()
{
if (!IsPostBack)
{
//Bind Date
}
}
或者,您可以
EnableEventValidation="false"
但這不建議
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.