0

Rowcommand button in gridview doesn't fire,

the data in the gridview retrieved from TB_DOCUMENT, i intend to get the value of the first column (DOC_ID) and stored it to another table as new record (TB_DOC) can somebody help me with this? Thanks

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>
invidicult
  • 306
  • 2
  • 8
  • 19
  • I assume that you DataBind the grid in `Page_Load` every time instead of only `If Not Page.IsPostBack`. – Tim Schmelter Jan 13 '15 at 09:18
  • What value does `Option Compare` have in your project? Your button in the html has the name `Select` but you're looking for `select` in the code behind. If `Option Compare` is set to binary, they won't match. – James Thorpe Jan 13 '15 at 09:19

1 Answers1

1

I ran your code the problem is that gridview command names are case-sensitive. Your RowCommand button in your gridview does fire but never passes your if then statement.

You have If e.CommandName = "select" Then

Try

If e.CommandName = "Select" Then

wolfeh
  • 666
  • 1
  • 8
  • 23