DataGrid Form de Alteração - VS2003
29/02/2008
0
Pessoal tenho datagrid com um checkbox onde escolho o item que desejo alterar (não quero fazer a alteração no datagrid), após selecionar o registro e clicar no botão OK é aberto o form de alteração justamente com os dados selecionados do Datagrid. Até tudo bem, mas não estou conseguindo agora excluir o registro.
Código do botão OK do datagrid
Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
For Each item As DataGridItem In Me.dgConsulta.Items
If item.ItemType = ListItemType.Item OrElse item.ItemType = ListItemType.AlternatingItem Then
Dim ckitem As CheckBox = DirectCast(item.FindControl(´CkItem´), CheckBox)
If ckitem.Checked Then
Me.Label2.Text &= item.Cells(1).Text
End If
End If
Next
Response.Redirect(´Alterar.aspx?id=´ + Label2.Text)
End sub
Código do botão Exlcuir no form de alteração
Private Sub btnexcluir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexcluir.Click
Me.MessageBox1.ShowConfirmation(´Deseja Mesmo Excluir?´, ´Excluir´, True, False)
End Sub
Private Sub MessageBox1_YesChoosed(ByVal sender As Object, ByVal Key As String) Handles MessageBox1.YesChoosed
If Key = ´Excluir´ Then
Dim drAux As DataRow()
drAux = AlterarDS1.Tables(´tbl_audio´).Select(´ID=´ + editID.Text) ´.Delete()
AlterarDS1.Tables(´tbl_audio´).Rows(editID.Text).Delete()
SqlDataAdapter1.Update(AlterarDS1)
DataBind()
End sub
Porém ao exceutar aparece a seguinte mensagem de erro
There is no row at position 168.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: There is no row at position 168.
Source Error:
Line 557: Private Sub MessageBox1_YesChoosed(ByVal sender As Object, ByVal Key As String) Handles MessageBox1.YesChoosed
Line 558: If Key = ´Excluir´ Then
Line 559: AlterarDS1.Tables(´tbl_audio´).Rows(editID.Text).Delete()
Line 560: SqlDataAdapter1.Update(AlterarDS1)
Line 561: DataBind()
Sei que é relacionado a posição do registro na tabela, mas não estou conseguindo resolver.
Julierme Felix
Código do botão OK do datagrid
Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
For Each item As DataGridItem In Me.dgConsulta.Items
If item.ItemType = ListItemType.Item OrElse item.ItemType = ListItemType.AlternatingItem Then
Dim ckitem As CheckBox = DirectCast(item.FindControl(´CkItem´), CheckBox)
If ckitem.Checked Then
Me.Label2.Text &= item.Cells(1).Text
End If
End If
Next
Response.Redirect(´Alterar.aspx?id=´ + Label2.Text)
End sub
Código do botão Exlcuir no form de alteração
Private Sub btnexcluir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexcluir.Click
Me.MessageBox1.ShowConfirmation(´Deseja Mesmo Excluir?´, ´Excluir´, True, False)
End Sub
Private Sub MessageBox1_YesChoosed(ByVal sender As Object, ByVal Key As String) Handles MessageBox1.YesChoosed
If Key = ´Excluir´ Then
Dim drAux As DataRow()
drAux = AlterarDS1.Tables(´tbl_audio´).Select(´ID=´ + editID.Text) ´.Delete()
AlterarDS1.Tables(´tbl_audio´).Rows(editID.Text).Delete()
SqlDataAdapter1.Update(AlterarDS1)
DataBind()
End sub
Porém ao exceutar aparece a seguinte mensagem de erro
There is no row at position 168.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: There is no row at position 168.
Source Error:
Line 557: Private Sub MessageBox1_YesChoosed(ByVal sender As Object, ByVal Key As String) Handles MessageBox1.YesChoosed
Line 558: If Key = ´Excluir´ Then
Line 559: AlterarDS1.Tables(´tbl_audio´).Rows(editID.Text).Delete()
Line 560: SqlDataAdapter1.Update(AlterarDS1)
Line 561: DataBind()
Sei que é relacionado a posição do registro na tabela, mas não estou conseguindo resolver.
Julierme Felix
Julierme
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)