GridView dv.Rowfilter

Signaler
Messages postés
19
Date d'inscription
jeudi 19 avril 2012
Statut
Membre
Dernière intervention
27 mai 2012
-
salut
comment faire pour changer cette commande dynamiquement c-a-d à chaque fois que je me connecte à une table les colonnes réagissent avec
dv.RowFilter = ("ShipName like" & SearchExpression & "or ShipAddress like" & SearchExpression &  "or ShipCountry like" & SearchExpression )


voila les deux fonctions
Private Sub SearchText()
        Dim value As String
        Dim dt As DataTable = recuperer()
        Dim dv As DataView = New DataView(dt)
        Dim SearchExpression As String = Nothing
        If Not String.IsNullOrEmpty(txtRecherche.Text) Then
            SearchExpression = String.Format("{0} '%{1}%'", GridView1.SortExpression, txtRecherche.Text)
        End If
        dv.RowFilter = ("ShipName like" & SearchExpression & "or ShipAddress like" & SearchExpression &  "or ShipCountry like" & SearchExpression )
 
        GridView1.DataSource = dv
 
        GridView1.DataBind()


Private Function recuperer() As DataTable
        Dim conn As SqlConnection = New SqlConnection("Data Source=MOUAD\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True")
        conn.Open()
        Dim cmd As SqlCommand = New SqlCommand
        cmd.Connection = conn
        cmd.CommandText = "select orderID,ShipName,ShipAddress,ShipCountry from Orders"
        Dim dAdapter As SqlDataAdapter = New SqlDataAdapter
        dAdapter.SelectCommand = cmd
        Dim objDs As DataSet = New DataSet
        dAdapter.Fill(objDs)
        Return objDs.Tables(0)
    End Function