我有這個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
什麼是問題及其解決方案,請幫助我。
在此先感謝。
首先,我想包在_Page_Load_代碼在'如果沒有的IsPostBack然後的GetList()'。 – 2013-03-14 09:56:36
它的工作原理!但是當我按下刪除按鈕時,它給了我'對象引用沒有設置爲對象的實例.' Dim strusername As String = CType(gvList.FindControl(「lblUsername」),Label).Text.Trim() '線。 – 7alhashmi 2013-03-14 10:03:47
你不需要在RowCommand事件中處理這個,並檢查CommandName = Delete。然後執行刪除並在那裏重新綁定它。您還應該將初始綁定放在回發檢查中如果Page.Ispostback = false,那麼 – 2013-03-14 13:00:33