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 28 29 30 31 32 33 34 35
| Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs) _
Handles dg.ItemCommand
If e.CommandName = "DelBatch" Then
Dim oItem As DataGridItem
Dim sKeys As New ArrayList
For Each oItem In dg.Items
If CType(oItem.FindControl("chkDel"), CheckBox).Checked Then
sKeys.Add(dg.DataKeys(oItem.ItemIndex).ToString)
End If
Next
If sKeys.Count <> 0 Then DelItems(sKeys)
End If
End If
Private Sub DelItems(ByVal sKeys As ArrayList)
Dim sKey As String
Dim sSQL As String = "Delete * From Humains Where "
For Each sKey In sKeys
sSQL &= String.Format("IDHumain={0} OR ", sKey)
Next
sSQL = sSQL.Substring(0, sSQL.Length - 4)
Dim oConn As New OleDb.OleDbConnection("le ConnectionString")
Dim oComm As New OleDb.OleDbCommand(sSQL, oConn)
Try
oConn.Open()
oComm.ExecuteNonQuery()
dg.EditItemIndex = -1
Catch ex As Exception
Finally
oComm.Dispose()
oConn.Close()
dg.CurrentPageIndex = 0
End Try
BindData()
End Sub |
Partager