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 :

sqlsdatasource paramétré selon un dropdownlist [Débutant]


Sujet :

ASP.NET

  1. #1
    Membre habitué
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Points : 175
    Points
    175
    Par défaut sqlsdatasource paramétré selon un dropdownlist
    Bonjour, prière de m'aider a resoudre ce probleme je me perd :

    j'ai une sqldatasource que je veux parametrer :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <asp:SqlDataSource ID="CorrespondancesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:DRE_kenitraConnectionString %>"
                                                SelectCommand="SELECT [Correspondance], [Observations] FROM [StationsServices] WHERE ([ID_station] = @ID_station)">
                                                <SelectParameters>
                                                    <asp:ControlParameter ControlID="hidTest" Name="ID_station" PropertyName="Value" Type="Int64" />
                                                </SelectParameters>
                                            </asp:SqlDataSource>
    avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <asp:DropDownList ID="ddlsta" runat="server" AutoPostBack="true" CssClass="txt" OnSelectedIndexChanged="ddlsta_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <asp:HiddenField ID="hidTest" runat="server" />
    et dans le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
        protected void ddlsta_SelectedIndexChanged(object sender, EventArgs e)
        {
            hidTest.Value = ddlsta.SelectedValue;
     
        }
    L'objectif est que le sqldatasource prend l'id du parametre selectionnée en haut et me fait sortir les lignes adequates a l'element selectionné

    j'ai fait tout ca et je recois l'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    : Impossible de trouver le contrôle 'hidTest' dans ControlParameter 'ID_station'.

  2. #2
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    Bonjour,

    J'allais poser la même question que toi, j'ai une Db oracle express, j'ai installé les developer tools oracle.

    J'ai une DropDownList:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <asp:SqlDataSource ID="dsProfils" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT ID_PROFIL, DESCRIPTION_PROFIL FROM TBL_PROFIL"></asp:SqlDataSource>
    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="dsProfils" DataTextField="DESCRIPTION_PROFIL" DataValueField="DESCRIPTION_PROFIL" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
    Ensuite j'ai un deuxième sqldatasource que je gère via l'assistant de configuration, mais il me sort une requête avec un ? dans mon where
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SELECT "NOM", "PRENOM", "DESCRIPTION_PROFIL", "PROFIL" FROM "VUE_RECRUTEMENT" WHERE ("DESCRIPTION_PROFIL" = ?)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
                SelectCommand="SELECT &quot;NOM&quot;, &quot;PRENOM&quot;, &quot;DESCRIPTION_PROFIL&quot;, &quot;PROFIL&quot; FROM &quot;VUE_RECRUTEMENT&quot; WHERE (&quot;DESCRIPTION_PROFIL&quot; = ?)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" Name="DESCRIPTION_PROFIL" PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>
    J'ai déjà essayé de modifier à la main la query dans SelectCommand.

    Es- tu aussi passer par l'assistant de visual studio ?

    J'obtiens donc une erreur ORA-00911: caractère non valide celle- ci est logique vu que je lui donne un ? en paramêtre, j'ai l'impression qu'il ne trouve pas le paramètre ControlID="DropDownList1" Name="DESCRIPTION_PROFIL"

  3. #3
    Membre habitué
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Points : 175
    Points
    175
    Par défaut
    Voila la solution je tester ai demain

    https://m.youtube.com/watch?v=8IFCiYIyLa4

  4. #4
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    Salut,

    La vidéo est intéressante pour un débutant comme moi, mais je ne pense pas que ça va résoudre mon problème, je regarderai ça en profondeur au soir, tiens moi au courant si de ton côté c'est résolu.

  5. #5
    Membre habitué
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Points : 175
    Points
    175
    Par défaut
    Bonjour, la vidéo m'a résolu le probleme j'ai recu ce que je veux mais j'ai un autre probleme :

    ma dropdownlist se trouve dans un autre tabpanel, donc j'ai changer un peu le code de tel sorte a ce que je recupere sa valeur dans un textbox, et j'ai reussi a recupéré la bonne valeur a chaque changement de la liste.

    mais je n'arrive pas a avoir ce que je veux au niveau de mon gridview qui est lié a la sqldatasource paramétré sachant que je n'ai aucune erreur au niveau du code.

    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
    28
    29
    30
    <asp:TabPanel ID="TabCorresp" runat="server" HeaderText="Correspondances">
                    <ContentTemplate>
                        <asp:GridView ID="GridCorresps" runat="server" AutoGenerateColumns="False" DataSourceID="CorrespsParStationSDS"
                            CellPadding="4" ForeColor="#333333" BorderColor="#E6E6E6" GridLines="Horizontal"
                            Width="700px" Style="font-size: 9pt; color: black; font-family: Arial">
                            <Columns>
                                <asp:BoundField DataField="Correspondance" HeaderText="Correspondance" SortExpression="Correspondance" />
                                <asp:BoundField DataField="Observations" HeaderText="Observations" SortExpression="Observations" />
                                <asp:BoundField DataField="ID_station" HeaderText="ID_station" InsertVisible="False"
                                    ReadOnly="True" SortExpression="ID_station" Visible="False" />
                            </Columns>
                            <EditRowStyle BackColor="#2461BF" />
                            <FooterStyle BackColor="#0066FF" Font-Bold="True" ForeColor="#e9e9e9" />
                            <HeaderStyle BackColor="#0066FF" Font-Bold="false" ForeColor="#e9e9e9" Font-Size="9" />
                            <PagerStyle BackColor="#0066FF" ForeColor="#e9e9e9" HorizontalAlign="Center" />
                            <RowStyle BackColor="#f3f3f3" Font-Size="9" />
                            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="false" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#F5F7FB" />
                            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                            <SortedDescendingCellStyle BackColor="#E9EBEF" />
                            <SortedDescendingHeaderStyle BackColor="#4870BE" />
                        </asp:GridView>
                        <asp:SqlDataSource ID="CorrespsParStationSDS" runat="server" ConnectionString="<%$ ConnectionStrings:access %>"
                            SelectCommand="SELECT [Correspondance], [Observations], [ID_station] FROM [StationsServices] WHERE ([ID_station] = @ID_station)">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="txtinvisible" Name="ID_station" PropertyName="Text" Type="Int64" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </ContentTemplate>
                </asp:TabPanel>
    veuillez m'aider ?

  6. #6
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    Re,

    Tu reviens sur le même problème que moi:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
                SelectCommand="SELECT [NOM], [PRENOM], [DESCRIPTION_PROFIL], [PROFIL] FROM [VUE_RECRUTEMENT] WHERE ([DESCRIPTION_PROFIL] = @DESCRIPTION_PROFIL)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" Name="DESCRIPTION_PROFIL" PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource2" AllowPaging="True" AllowSorting="True">
    J'ai voulu faire la query via l'assistance de visual studio mais ça ne fonctionnait pas il me mettait:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SelectCommand="SELECT NOM, PRENOM, DESCRIPTION_PROFIL, PROFIL FROM VUE_RECRUTEMENT WHERE DESCRIPTION_PROFIL = ?">
    alors que j'aurais dû avoir
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SelectCommand="SELECT [NOM], [PRENOM], [DESCRIPTION_PROFIL], [PROFIL] FROM [VUE_RECRUTEMENT] WHERE ([DESCRIPTION_PROFIL] = @DESCRIPTION_PROFIL)">
    je l'ai donc ecrit à la main.

    mais ça ne fonctionne pas erreur: ORA-00936: expression absente

    Si je fais
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SelectCommand="SELECT NOM, PRENOM, DESCRIPTION_PROFIL, PROFIL FROM VUE_RECRUTEMENT WHERE DESCRIPTION_PROFIL = 'Informaticien'">
    là ça fonctionne mais je voudrais lui passer le paramètre de ma DropDownList1

    Que faire ?

  7. #7
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    Si j'ajoute dans le code behind

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
            {
                SqlDataSource2.SelectCommand = "SELECT NOM, PRENOM, DESCRIPTION_PROFIL, PROFIL FROM VUE_RECRUTEMENT WHERE DESCRIPTION_PROFIL = '" + DropDownList1.SelectedValue + "'";
            }
    ça fonctionne mais j'aurais voulu le mettre dans le fichier .aspx comme dans le doc que je lis.

    Que faut-il utiliser et comment faire via le code .aspx ??

  8. #8
    Membre habitué
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Points : 175
    Points
    175
    Par défaut
    J ai mis ma gridview dans un update panel et ca marche pour moi

  9. #9
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    Moi ça ne fonctionne toujours pas, et y a personne pour m'aider

    Help please

  10. #10
    Membre habitué
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Points : 175
    Points
    175
    Par défaut
    J ai cru que ton probleme est resolu.tu peux poster le code du dropdown,SQL data et gridview ???

  11. #11
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    Voici le code de ma page .aspx

    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
    28
    29
    30
    31
     
    <!DOCTYPE html>
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
     
        </div>
            <asp:SqlDataSource ID="dsProfils" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT ID_PROFIL, DESCRIPTION_PROFIL FROM TBL_PROFIL"></asp:SqlDataSource>
            .<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="dsProfils" DataTextField="DESCRIPTION_PROFIL" DataValueField="DESCRIPTION_PROFIL" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT &quot;NOM&quot;, &quot;PRENOM&quot;, &quot;DESCRIPTION_PROFIL&quot;, &quot;PROFIL&quot; FROM &quot;VUE_RECRUTEMENT&quot; WHERE ((&quot;DESCRIPTION_PROFIL&quot; = ?) AND (&quot;DESCRIPTION_PROFIL&quot; = ?))">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="DropDownList1" Name="DESCRIPTION_PROFIL" PropertyName="SelectedValue" Type="String" />
                            <asp:ControlParameter ControlID="DropDownList1" Name="DESCRIPTION_PROFIL2" PropertyName="SelectedValue" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
                    </asp:DataList>
                </ContentTemplate>
            </asp:UpdatePanel>
        </form>
    </body>
    </html>

  12. #12
    Membre habitué
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Points : 175
    Points
    175
    Par défaut
    Apparement ton sqldatasource contient quelqu es choses qui ne va pas.

    Est ce que tu peux atteindre ton dropdown en mode design ???

  13. #13
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    Merci de ton aide Msysteme, ou en mode désign je sais atteindre le contrôle DropDownList, si je retire le code de mon deuxième sqldatasource je sais exécuter ma page web sans problème et ma DroDonwList se remplit bien. Je vois pas bien ce qu'il cloche !!

    Regarde mon print screen Nom : 1.PNG
Affichages : 110
Taille : 58,6 Ko

  14. #14
    Membre habitué
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Points : 175
    Points
    175
    Par défaut
    Si tu met ajouter et tu enlever le ? Dane le code qu'est ce qui se passe ?
    Si tu met ajouter et tu enlever le ? Dane le code qu'est ce qui se passe ?

    Si tu change ton sqldatasource 1 par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    SelectCommand="SELECT [NOM], [PRENOM], [DESCRIPTION_PROFIL], [PROFIL] FROM [VUE_RECRUTEMENT] WHERE ([DESCRIPTION_PROFIL] = @DESCRIPTION_PROFIL)">

  15. #15
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    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
    <body>
        <form id="form1" runat="server">
        <div>
     
        </div>
            <asp:SqlDataSource ID="dsProfils" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT ID_PROFIL, DESCRIPTION_PROFIL FROM TBL_PROFIL"></asp:SqlDataSource>
            .<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="dsProfils" DataTextField="DESCRIPTION_PROFIL" DataValueField="DESCRIPTION_PROFIL" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
                        SelectCommand="SELECT [NOM], [PRENOM], [DESCRIPTION_PROFIL], [PROFIL] FROM [VUE_RECRUTEMENT] WHERE ([DESCRIPTION_PROFIL] = @DESCRIPTION_PROFIL)">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="DropDownList1" Name="DESCRIPTION_PROFIL" PropertyName="SelectedValue" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
                    </asp:DataList>
        </form>
    </body>
    J'ai une erreur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    ORA-00936: expression absente
     
    Description : Une exception non gérée s'est produite au moment de l'exécution de la requête Web actuelle. Contrôlez la trace de la pile pour plus d'informations sur l'erreur et son origine dans le code. 
     
    Détails de l'exception: Oracle.ManagedDataAccess.Client.OracleException: ORA-00936: expression absente
    C'est surement une bêtise mais laquelle ?

    Le pire c'est que avec cette query
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
       SelectCommand="SELECT NOM, PRENOM, DESCRIPTION_PROFIL, PROFIL FROM VUE_RECRUTEMENT WHERE DESCRIPTION_PROFIL = 'Informaticien'">
    ça fonctionne

  16. #16
    Membre actif
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2006
    Messages : 661
    Points : 244
    Points
    244
    Par défaut
    Bonjour Msysteme,

    Je vais créer un autre poste pour arrêter de polluer le tiens qui est déjà en résolu

    Merci de ton aide

  17. #17
    Membre habitué
    Inscrit en
    Août 2008
    Messages
    1 596
    Détails du profil
    Informations forums :
    Inscription : Août 2008
    Messages : 1 596
    Points : 175
    Points
    175
    Par défaut
    Ne dis pas ca j aurais aimė t'aider Mais moi Aussi je ne vois pas ou est ton probleme.
    Ca se peut que c'est dans dsprofil que tu as le probleme parce que quand tu met 'informaticien' et ca fonctionne cela implique que la valeur selectionnėe n'atteint pas le sqldatasource

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

Discussions similaires

  1. Réponses: 6
    Dernier message: 23/07/2012, 18h47
  2. Changer un paramètre selon navigateur
    Par zesavantfou dans le forum Balisage (X)HTML et validation W3C
    Réponses: 9
    Dernier message: 17/09/2009, 19h35
  3. Réponses: 7
    Dernier message: 10/07/2006, 13h21
  4. Réponses: 10
    Dernier message: 10/05/2006, 22h04
  5. Requête Paramétrée avec DropDownList
    Par kirgan dans le forum Access
    Réponses: 2
    Dernier message: 24/04/2006, 16h22

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