求助,GridView使用Button删除行得问题!!!!!!!
我在模板里边添加了一个button
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
Dim id As Integer = GridView1.DataKeys(e.RowIndex).Value
Dim adapter As New ArticleSetTableAdapters.Table1TableAdapter()
adapter.Delete(id)
Response.Redirect( "/control.aspx ")
End Sub
使用gridview自带得删除功能可以删除
但是在button得 click事件里边添加
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim u As String = CType(sender, Button).CommandArgument()
Dim adapter As New ArticleSetTableAdapters.Table1TableAdapter()
adapter.Delete(u)
这样就有错误
请高手赐教
错误是
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation= "true "/> in configuration or <%@ Page EnableEventValidation= "true " %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
------解决方案--------------------protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in gvLoans.Rows)
{
CheckBox chk = (CheckBox)gvr.Cells[1].FindControl( "chk ");
if (chk.Checked)
{
gvLoans.DeleteRow(gvr.RowIndex);
}
}
}