I still muddled with some things (that is with a lot of them). I have a Gridview, where the first column ia a TemplateField with a LinkButton to delete the record, the selected row.
I did the same routine using the primary key with DataKeyNames, however in this case the GridView, was populated manually and now I'm using curl.
I did the following:
Private Sub GrdDocumentos_RowCommand (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GrdDocumentos.RowCommand 'Can I exclude here in RowCommand If e.CommandName = "Delete" Then RelID GrdDocumentos.SelectedRow.Cells = (4). Text (does not work that way) 'GrdDocumentos.SelectedIndex = SelectedGridRow.RowIndex 'Delete the record 'Implement this on your own:) DeleteRecordByID (relID) End If End Sub
Private Sub DeleteRecordByID (ByVal RegID As Integer) Dim Sql As String Dim cmd As SqlCommand Dim connection As SqlConnection connection = New SqlConnection (ConfigurationManager.ConnectionStrings ( "Timesheet"). ConnectionString) Sql = "DELETE FROM REL_PROJETOS" Sql + = "WHERE REL_ID =" & RegID cmd = New SqlCommand (Sql, connection) Try conexao.Open () cmd.Connection = connection cmd.CommandType = CommandType.Text cmd.CommandText = Sql cmd.ExecuteNonQuery () Catch ex As Exception lblMensagem.Text = "Error Occurred While Deleting:" & vbCrLf & ex.Message & vbCrLf '& ex.InnerException.ToString Finally conexao.Close () GrdDocumentos.DataBind () End Try End Sub Protected Sub GrdDocumentos_SelectedIndexChanging (ByVal sender As Object, ByVal e As System.EventArgs) Handles GrdDocumentos.SelectedIndexChanged RelID = GrdDocumentos.SelectedRow.Cells (12). Text End Sub
Then I need to get the ID to be able to delete the desired record.
Thanks and a hug