Supression d'enregistrement d'un DataGridView
Bonjour à tous,
En suivant mon aventure avec le DataGridView, j'ai reussi à faire un ButtonField que marche bien, il bien efface les donnés de ma base, mais il n'efface pas la ligne du DataGridView.
Il faut rafraichir la page manuellement pour qu'il s'efface du GridView.
J'ai essayé plusieurs solutions, mais aucune semble à marcher...
:arf:
Voilà mes codes:
Code:
1 2 3 4 5
| <asp:GridView ID="lstDemandes" runat="server">
<Columns>
<asp:ButtonField CommandName="delete" Text="Supprimer" />
</Columns>
</asp:GridView> |
Le code-behind:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| If (e.CommandName = "delete") Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = Me.lstDemandes.Rows(index)
strSQL = "SELECT T_demande_formation.* " & _
"FROM T_demande_formation " & _
"WHERE T_demande_formation.Demande=" & row.Cells(1).Text
ObjetConnection = New OleDbConnection()
ObjetConnection.ConnectionString = DRHConn
ObjetConnection.Open()
ObjetCommand = New OleDbCommand(strSQL)
ObjetCommand.CommandTimeout = 0
ObjetDataAdapter = New OleDbDataAdapter(ObjetCommand)
ObjetCommand.Connection() = ObjetConnection
ObjetDataAdapter.Fill(ObjetDataSet, "T_demande_formation")
ObjetDataTable = ObjetDataSet.Tables("T_demande_formation")
Try
ObjetDataTable.Rows(0).Delete()
ObjetCommandBuilder = New OleDbCommandBuilder(ObjetDataAdapter)
ObjetDataAdapter.Update(ObjetDataSet, "T_demande_formation")
ObjetConnection = Nothing
ObjetCommand = Nothing
ObjetDataAdapter = Nothing
Response.Redirect("frmDemandes.aspx")
Catch
Response.Write("Erreur 00000055: Erreur de connexion")
End Try
End If |
Je vous remercie en avance...