我试图在从数据库中删除之前保存一些信息。我正在使用asp gridview。我正在尝试从使用 RowDeleting 事件删除的行中检索值。然而,我非常失败。
Protected Sub gv1_RowDeleting(sender As Object, e As System.EventArgs) Handles gv1.RowDeleting
Dim a As String = gv1.Columns(0).ToString
Dim b As String = gv1.SelectedRow.RowIndex.ToString
Dim c As String = gv1.Rows(a).Cells(0).Text
End Sub
a 最终成为标题行的第一列。b 出错了。我尝试了很多不同的东西,但无法提出行索引。我会认为这个事件只会访问被删除的行。这是我的gridview声明:
<asp:GridView ID="gv1" runat="server" AllowSorting="True" AutoGenerateColumns="False" EnableViewState="false"
DataSourceID="ds1" EmptyDataText="NO ROWS FOUND" CssClass="gridView" DataKeyNames="id" GridLines="None">
<Columns>
<asp:BoundField DataField="id" HeaderText="ID" SortExpression="id" />
<asp:BoundField DataField="totalsd" HeaderText="SD" SortExpression="totalsd" />
<asp:BoundField DataField="freesd" HeaderText="FREE" SortExpression="freesd" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this record?');" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>