IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

[Vb.net].[datagrid] Master datagrid


Sujet :

ASP.NET

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    121
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Septembre 2005
    Messages : 121
    Points : 56
    Points
    56
    Par défaut [Vb.net].[datagrid] Master datagrid
    bonjour, je travaile avec web matrix, et j'ai 2 datagrids lié. Lorsque je choisi une ligne de la 1ere, la 2ème ouvre la table correspondante au choix.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      Dim nom_test As String = CStr(MasterGrid.DataKeys(MasterGrid.SelectedIndex)).Replace("'", "''")
    ici on recupere le nom du test de la 1ere datagrid

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Dim CommandText As String = "select * from " & nom_test & " where [N° de Tri]=" & num_tri
    je voudrais récuperer un 2e parametre de la 1ère datagrid (num tri) mais je ne sais pas trop comment faire. sachant quil etait a la 5e colonne jai essayé ca :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Dim num_tri As String = CStr(MasterGrid.Columns(5)(MasterGrid.SelectedIndex)).Replace("'", "''")
    mais ca ne marche pas

    des idées ?
    "One should never increase, beyond what is necessary,
    the number of entities required to explain anything."

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    121
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Septembre 2005
    Messages : 121
    Points : 56
    Points
    56
    Par défaut
    bonjour,

    je met en plus la partie de mon code sur le 2e datagrid, j'espere que cela pourra vous aider...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Sub BindDetailGrid()
    
        ' get the filter value from the master Grid's DataKeys collection
        If MasterGrid.SelectedIndex <> -1 Then
    
            ' TODO: update the ConnectionString value for your application
            Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=Y:\bd\mirroir_bd_mobile.mdb"
    
            ' TODO: update the CommandText value for your application
            Dim nom_test As String = CStr(MasterGrid.DataKeys(MasterGrid.SelectedIndex)).Replace("'", "''")
            Dim num_tri as string = "333"
            Dim CommandText As String = "select * from " & nom_test & " where [N° de Tri]=" & num_tri
    
            Dim myConnection As New OledbConnection(ConnectionString)
            Dim myCommand As New OledbCommand(CommandText, myConnection)
    
            myConnection.Open()
    
            DetailsGrid.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
    
        End If
    
        DetailsGrid.DataBind()
    
    End Sub

    voila, j'aimerai dans la variable numtri, on est le contenu d'une cellule d'une autre datagrid, appelé masterdatagrid. comment faire ?
    "One should never increase, beyond what is necessary,
    the number of entities required to explain anything."

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    121
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Septembre 2005
    Messages : 121
    Points : 56
    Points
    56
    Par défaut
    J'ai enfin reussi ,

    je met mon code si ca peut aider certaine personne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Sub BindDetailGrid()
    
        ' get the filter value from the master Grid's DataKeys collection
        If MasterGrid.SelectedIndex <> -1 Then
    
            response.write(MasterGrid.SelectedIndex)
            ' TODO: update the ConnectionString value for your application
            Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=Y:\bd\mirroir_bd_mobile.mdb"
    
            ' TODO: update the CommandText value for your application
            Dim nom_test As String = CStr(MasterGrid.DataKeys(MasterGrid.SelectedIndex)).Replace("'", "''")
         
            Dim num_tri = MasterGrid.items(MasterGrid.SelectedIndex).cells(5).text
            Dim CommandText As String = "select * from " & nom_test & " where [N° de Tri]=" & num_tri
    
            Dim myConnection As New OledbConnection(ConnectionString)
            Dim myCommand As New OledbCommand(CommandText, myConnection)
    
            myConnection.Open()
    
            DetailsGrid.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
    
        End If
    
        DetailsGrid.DataBind()
    
    End Sub
    la ligne en bleu me permet de recuperer un champ de la premiere table et donc ma requete peut etre plus souple : Le Datakey me permet de choisir la table a interoger, et le numtri de me ballader dans cette table.
    "One should never increase, beyond what is necessary,
    the number of entities required to explain anything."

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [VB.NET] Remplir un DataGrid manuellement ?
    Par dinbougre dans le forum Windows Forms
    Réponses: 9
    Dernier message: 04/02/2005, 18h29
  2. [VB.NET] Exception si DataGrid mis a jour
    Par florent_g dans le forum Windows Forms
    Réponses: 1
    Dernier message: 25/10/2004, 12h00
  3. [VB.NET][DataBinding] Rafraichissement DataGrid lié à un obj
    Par speedy1496 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 21/10/2004, 10h15
  4. [VB.NET] Binder ToolTip DataGrid
    Par sg-40 dans le forum ASP.NET
    Réponses: 3
    Dernier message: 16/07/2004, 13h56
  5. Réponses: 12
    Dernier message: 18/03/2004, 15h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo