I am trying to obtain the row index on a button click in an asp gridview.
<asp:Panel runat="server" Visible="true" ID="pnlGV">
<asp:GridView ID="gvTasks" runat="server" CssClass="table table-hover table-striped" DataKeyNames="TaskID" AutoGenerateColumns="False" AllowPaging="true" AllowSorting="true" PageSize="10" SkinID="standard_gv" EmptyDataText="No tasks match your search terms">
<Columns>
<asp:BoundField SortExpression="TaskID" DataField="TaskID" ReadOnly="true" HeaderText="Task ID" />
<asp:BoundField SortExpression="ProjectCode" DataField="ProjectCode" ReadOnly="true" HeaderText="Project Code" />
<asp:BoundField SortExpression="TaskType" DataField="TaskType" ReadOnly="true" HeaderText="Task Type" />
<asp:BoundField SortExpression="TaskDescription" DataField="TaskDescription" ReadOnly="true" HeaderText="Description" />
<asp:BoundField SortExpression="BizArea" DataField="BizArea" ReadOnly="true" HeaderText="Business Area" />
<asp:BoundField SortExpression="TargetDate" DataField="TargetDate" ReadOnly="true" HeaderText="Target" />
<asp:BoundField SortExpression="TaskStatus" DataField="TaskStatus" ReadOnly="true" HeaderText="Status" />
<asp:BoundField SortExpression="TaskPriority" DataField="TaskPriority" ReadOnly="true" HeaderText="Priority" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnNotes" runat="server" CommandName="notes" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>" Text="Notes" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
and
Protected Sub gvTasks_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
Try
If (e.CommandName = "notes") Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = gvTasks.Rows(index)
notesAcc.Populate(CInt(gvTasks.Rows(index).Cells(0).Text))
notesAcc.Visible = True
End If
Catch ex As Exception
Throw
End Try
End Sub
This just throws this error message at me:
Invalid postback or callback argument. Event validation is enabled using 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.
and I have no idea how to fix it.
Would anyone be able to give me some insight?
Thank you in advance.
Tom
Edit: Thank you for the responses, it is much appreciated.
What is notesAcc.Populate(CInt(gvTasks.Rows(index).Cells(0).Text)) dong? If you comment it out does the problem go away?
That is calling a Sub from an .ascx file, and I wouldn't imagine so as I've breakpointed the event handler and it doesn't even reach it.
Do you get that error when page loads or when you click the button?
When I click the button.
It is probably worth mentioning that I am no longer getting the error. I made a tiny insignificant change - so small I can't even remember what it was - and it's gone away, however, it's still not working as intended. The event handler doesn't trigger and I have no idea why. Again, would anyone be able to give me a nudge in the right direction?