我有这个gridview,我不知道里面的按钮有什么问题。我有这个 asp 代码:
<asp:GridView ID="gvList" runat="server">
<Columns>
<asp:TemplateField HeaderText="User Name" HeaderStyle-ForeColor="Black" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Label runat="server" ID="lblUsername" Text='<%# Eval("cUserName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dept User" HeaderStyle-ForeColor="Black" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Label runat="server" ID="lblDept" Text='<%# iif(Eval("lDeptUser"),"Yes","No") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Actions" HeaderStyle-ForeColor="black" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Button ID="btnedit" runat="server" Text="Edit" />
<asp:Button ID="btnDelete" OnClick="DeleteRow" runat="server" Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
当我在任何行上按删除或编辑时,它会给我错误!Invalid postback or callback argument.
这是我在 vb.net 中的服务器端代码:
Public Function GetList() As DataTable
Dim Query As String = "Select cUserName,lDeptUser FROM Intranet.dbo.Gn_ISCoordinators"
Dim dt As DataTable = New DataTable()
Using adapter = New SqlDataAdapter(Query, ConfigurationManager.ConnectionStrings("IntranetConnectionString").ConnectionString)
adapter.Fill(dt)
gvList.DataSource = dt
gvList.DataBind()
Return dt
End Using
End Function
Public Function DelRow() As DataTable
Dim strusername As String = CType(gvList.FindControl("lblUsername"), Label).Text.Trim()
Dim Query As String = "Delete FROM Intranet.dbo.Gn_ISCoordinators where cUserName='" & strusername & "'"
Dim dt As DataTable = New DataTable()
Using Adapter = New SqlDataAdapter(Query, ConfigurationManager.ConnectionStrings("IntranetConnectionString").ConnectionString)
Adapter.Fill(dt)
Return dt
End Using
End Function
Protected Sub DeleteRow(ByVal sender As Object, ByVal e As System.EventArgs)
DelRow()
End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
GetList()
End Sub
Protected Sub gv(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvList.RowDataBound
e.Row.Cells(3).Visible = False
e.Row.Cells(4).Visible = False
End Sub
End Class
我认为它来自客户端。请帮我解决这个问题。顺便说一句,到目前为止我还没有使用任何 ajaxtoolkit,EnableEventValidation="true"
在页面中以及 web.config
是什么问题及其解决方法,请帮助我。
提前致谢。