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 36 37 38
| Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Si la page n'a pas déja été chargée
If Not (IsPostBack) Then
'tri en fonction de idProjet du dataGrid
BindGrid("idProjet")
End If
End Sub
' propriété onSortCommand personnalisé du dataGrid, prend en parametre un objet
Sub MyDataGrid_Sort(ByVal Src As Object, ByVal E As DataGridSortCommandEventArgs)
BindGrid(E.SortExpression)
End Sub
'procedure qui prend en parametre un string qui represente le critère de tri, on crée une connexion à la base
Sub BindGrid(ByVal SortField As String)
'on recupere la variable de session salarie, c'est l'utilisateur connecté
Dim sal2 As Salarie = CType(Session.Item("Sal"), Salarie)
'nouvelle connexion
Dim MyConnection As SqlConnection
MyConnection = New SqlConnection("server=(local);database=RDTEST;user ID=sa;pwd=")
Dim DS As DataSet
Dim MyCommand As SqlDataAdapter
'requete
MyCommand = New SqlDataAdapter("SELECT idProjet, libelleProjet, dateDebutProjet, nomSociete, evolutionProjet FROM Projet, Societe WHERE idService='" & sal2.getIdService.ToString & "' AND Projet.idSocieteDemandeuse=Societe.idSociete", MyConnection)
DS = New DataSet
MyCommand.Fill(DS, "Projet")
Dim Source As DataView = DS.Tables("Projet").DefaultView
Source.Sort = SortField
'on spécifie la source de données du dataGrid
MyDataGrid.DataSource = Source
'On met à jour le dataGrid
MyDataGrid.DataBind()
End Sub |
Partager