gridview中的Rowcommand按钮不会触发,
从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 Markup
<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>
答案 0 :(得分:1)
我运行你的代码问题是gridview命令名称区分大小写。您的gridview中的RowCommand按钮会触发,但从不传递if then语句。
你有 如果e.CommandName =&#34;选择&#34;然后尝试
如果e.CommandName =&#34;选择&#34;然后