0

gridview 中的行命令按钮不会触发,

从 TB_DOCUMENT 检索的 gridview 中的数据,我打算获取第一列 (DOC_ID) 的值并将其作为新记录 (TB_DOC) 存储到另一个表中,有人可以帮我解决这个问题吗?谢谢

Private Sub GridViewFile_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GridViewFile.RowCommand

    Dim rowIndex As Integer = Convert.ToInt32(e.CommandArgument)
    Dim id As Integer = Convert.ToInt32(GridViewFile.DataKeys(rowIndex).Values(0))

    If e.CommandName = "select" Then

        strSQL = "Insert into TB_Doc (NO,DOCID) value ('" & lblNoSUbReq.Text & "','" & id.ToString & "' )"
        clsDB.QueryExecuteNonQuery(strSQL)

    End If
End Sub

HTM 标记

<asp:GridView ID="GridViewFile" runat="server" AutoGenerateColumns="False" 
                   DataKeyNames="DOC_ID" DataSourceID="SqlDataDocs" BackColor="White" 
                   CellPadding="3" Width="100%" >

                        <Columns>
                            <asp:BoundField DataField="DOC_ID" HeaderText="DOC_ID" 
                                            ReadOnly="True" SortExpression="DOC_ID">

                            </asp:BoundField>

                            <asp:BoundField DataField="FILENAME" HeaderText="File Name" SortExpression="FILENAME" />
                            <asp:BoundField DataField="FILE_LOCATION" HeaderText="File Location" 
                                            SortExpression="FILE_LOCATION" HeaderStyle-CssClass="hiddencol" 
                                            ItemStyle-CssClass="hiddencol" >
                                            <HeaderStyle CssClass="hiddencol"></HeaderStyle>
                                            <ItemStyle CssClass="hiddencol"></ItemStyle>
                             </asp:BoundField>

                             <asp:ButtonField CommandName="Select" Text="Select" ButtonType="Button" />

                         </Columns>

</asp:GridView>
4

1 回答 1

1

我运行了您的代码,问题是 gridview 命令名称区分大小写。您的 gridview 中的 RowCommand 按钮会触发,但不会通过您的 if then 语句。

你有 If e.CommandName = "select" Then

尝试

如果 e.CommandName = "Select" 那么

于 2015-01-13T12:42:24.443 回答