Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Ola Amigos
Ainda me atrapalho com algumas coisas (quer dizer com um monte delas). Tenho um GridView, onde a primeira coluna e um TemplateField com um LinkButton, para excluir o registro, da linha selecionada.
Fiz a mesma rotina usando uma chave primaria DataKeyNames o COM, porem nesse caso o GridView, foi populado manualmente e agora estou meio enrolado.
Fiz o seguinte:
Protected Sub GrdDocumentos_RowDataBound (sender Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GrdDocumentos.RowDataBound
Se e.Row.RowType DataControlRowType.DataRow = Então
Dim L As LinkButton = DirectCast (e.Row.FindControl (LinkButton1 "), LinkButton)
l.Attributes.Add ( "onclick", ( "javascript: return" & "confirm ( 'Deseja Realmente Excluir o documento") & DataBinder.Eval (e.Row.DataItem ", REL_DOCUMENTO") & "?')")
End If
End Sub
Protected Sub GrdDocumentos_RowCommand (sender Object, ByVal e As System.Web.UI.WebControls.GridViewComandoEventArgs) Handles GrdDocumentos.RowCommand
"Posso excluir aqui no RowCommand
Se e.CommandName = "Excluir" Then
Relid = GrdDocumentos.SelectedRow.Cells (4). De texto (não funciona desse jeito)
'GrdDocumentos.SelectedIndex = SelectedGridRow.RowIndex
'Record Excluir
"Implementar esta em seu próprio país:)
DeleteRecordByID (relid)
End If
End Sub
Private Sub DeleteRecordByID (ByVal RegID As Integer)
Dim Sql As String
Dim cmd As SqlCommand
Dim conexao As SqlConnection
conexao = New SqlConnection (ConfigurationManager.ConnectionStrings (folha de ponto "). ConnectionString)
Sql = "DELETE FROM REL_PROJETOS"
Sql + = "WHERE REL_ID =" & RegID
cmd = New SqlCommand (Sql, conexao)
Tentar
conexao.Open ()
cmd.Connection = conexao
cmd.CommandType = CommandType.Text
cmd.CommandText = Sql
cmd.ExecuteNonQuery ()
Catch ex As Exception
lblMensagem.Text = "Ocorreu um Erro Durante a Exclusão:" & vbCrLf & ex.Message & vbCrLf '& ex.InnerException.ToString
Finalmente
conexao.Close ()
GrdDocumentos.DataBind ()
End Try
End Sub
Protected Sub GrdDocumentos_SelectedIndexChanging (sender Object, ByVal e As System.EventArgs) Handles GrdDocumentos.SelectedIndexChanged
Relid = GrdDocumentos.SelectedRow.Cells (12). Texto
End Sub
Portanto preciso pegar o ID para poder excluir o registro desejado.
Obrigado e um abraçoCarregando comentários...