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 :

Récupérer des données en cliquant sur le bouton ?


Sujet :

ASP.NET

  1. #1
    Membre à l'essai Avatar de Hawk_
    Homme Profil pro
    YouTuber
    Inscrit en
    Septembre 2016
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : YouTuber

    Informations forums :
    Inscription : Septembre 2016
    Messages : 35
    Points : 16
    Points
    16
    Par défaut Récupérer des données en cliquant sur le bouton ?
    Bonjour,



    Actuellement, je travaille sur un projet en ASP.net en C# et j'ai un petit soucis au niveau des boutons...

    Je m'explique :

    J'ai une page sur laquelle j'ai une TextBox, un label et un bouton jusque la rien de bien compliqué, ensuite en dessous j'ai une GridView qui doit s'afficher lorsque j'ai rentré une information dans ma TextBox, en l'occurrence un numéro de compte bancaire, et lorsque je clique sur le bouton la GridView doit s'afficher avec ce qu'elle récupère dans la base de donnée SQLDataSource.



    Donc lorsque je rentre le numéro de compte et que je valide sur le bouton, une liste doit s'afficher avec le Prénom / Nom de la personne titulaire du compte.

    Toutes les requêtes sont déjà mis en place sur SQLServer, donc je n'ai plus qu'à configurer mon bouton mais je ne sais pas quoi mettre pour l’exécuter.



    Voici le code de la page :

    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
    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
        <br />
        <asp:Label ID="Label1" runat="server" Text="Numéro de compte :"></asp:Label>
        <asp:TextBox ID="TextBox_num_compte" runat="server"></asp:TextBox> <br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server"></asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ContactClientConnectionString %>" SelectCommand="WF_Recherche_Client" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:ControlParameter ControlID="TextBox_num_compte" Name="Numcpt" PropertyName="Text" Type="String" />
                <asp:Parameter Name="Nom" Type="String" />
                <asp:Parameter Name="Prenom" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
    </asp:Content>


    Et au niveau du bouton :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    namespace Reamenagement_Prets
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
               ???
            }
        }
    }
    Merci pour votre aide.

    Cordialement.

  2. #2
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2016
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2016
    Messages : 147
    Points : 81
    Points
    81
    Par défaut
    Salut,

    Ne le met pas dans le Load mais sur l’événement Click

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
     
    SqlDataSource1.ConnectionString = ""
    SqlDataSource1.SelectCommand = ""
     
        End Sub
    Je ne sais pas si cela répond un peu ?

  3. #3
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2016
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2016
    Messages : 147
    Points : 81
    Points
    81
    Par défaut
    Désolé j'ai répondu en VB ça ira pour la traduction en C# ?

  4. #4
    Membre à l'essai Avatar de Hawk_
    Homme Profil pro
    YouTuber
    Inscrit en
    Septembre 2016
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : YouTuber

    Informations forums :
    Inscription : Septembre 2016
    Messages : 35
    Points : 16
    Points
    16
    Par défaut
    Citation Envoyé par dwlapp Voir le message
    Désolé j'ai répondu en VB ça ira pour la traduction en C# ?
    Je préférerais en C# si possible...

    Et je ne comprends pas bien.. Je suis débutant, ou ce situe l’événement click ?
    A cet endroit ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     protected void Button1_Click(object sender, EventArgs e)
            {
     
            }

  5. #5
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2016
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2016
    Messages : 147
    Points : 81
    Points
    81
    Par défaut
    Normalement en C# c'est comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
            protected void Button1_Click(object sender, EventArgs e)
            {
     
                SqlDataSource1.ConnectionString = "";
                SqlDataSource1.SelectCommand = "";
     
            }
    Pour accéder à l'évenement en c# tu dois allez dans les propriété du bouton tu cliques sur l'éclair ^^ et ensuite double click sur l'évènement click. Dur d'expliquer personne d'autre sait mieux que moi ? Moi en VB dans mon code en haut je choisis le bouton et l'évènement associé.

    Essaye de trouver les propriétés de ton bouton (en mode design au pire).

    Dis moi si tu trouve.

  6. #6
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2016
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2016
    Messages : 147
    Points : 81
    Points
    81
    Par défaut
    et oui à cet endroit :

    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
    namespace WebApplicationForum
    {
        public partial class test : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
     
     
     
            }
     
            protected void Button1_Click(object sender, EventArgs e)
            {
     
                SqlDataSource1.ConnectionString = "";
                SqlDataSource1.SelectCommand = "";
     
            }
        }
    }

  7. #7
    Membre à l'essai Avatar de Hawk_
    Homme Profil pro
    YouTuber
    Inscrit en
    Septembre 2016
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : YouTuber

    Informations forums :
    Inscription : Septembre 2016
    Messages : 35
    Points : 16
    Points
    16
    Par défaut
    Citation Envoyé par dwlapp Voir le message
    et oui à cet endroit :

    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
    namespace WebApplicationForum
    {
        public partial class test : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
     
     
     
            }
     
            protected void Button1_Click(object sender, EventArgs e)
            {
     
                SqlDataSource1.ConnectionString = "";
                SqlDataSource1.SelectCommand = "";
     
            }
        }
    }
    Houraaaaa ! Avec persévérance je suis arrivé à mes fins !!

    Donc j'ai tout simplement fait un Databind de ma GridView dans mon événement click :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    protected void Button1_Click(object sender, EventArgs e)
            {
                GridView1.DataBind();
            }
    Et ensuite dans ma SqlDataSource j'ai fait mes commandes :
    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
     protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
            {
                if (TextBox_num_compte.Text == "" && TextBox_Nom_Partenaire.Text == "" && TextBox_Prenom_Part.Text == "")
                {
                    // Erreur
                    string abc = "";
                }
                else
                {
                    if (TextBox_num_compte.Text == "")
                        e.Command.Parameters["@Numcpt"].Value = '%';
                    else
                        e.Command.Parameters["@Numcpt"].Value = TextBox_num_compte.Text;
     
                    if (TextBox_Nom_Partenaire.Text == "")
                        e.Command.Parameters["@Nom"].Value = '%';
                    else
                        e.Command.Parameters["@Nom"].Value = TextBox_Nom_Partenaire.Text;
     
                    if (TextBox_Prenom_Part.Text == "")
                        e.Command.Parameters["@Prenom"].Value = '%';
                    else
                        e.Command.Parameters["@Prenom"].Value = TextBox_Prenom_Part.Text;
                }
     
            }

  8. #8
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2016
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2016
    Messages : 147
    Points : 81
    Points
    81
    Par défaut
    Ok parfait

  9. #9
    Membre à l'essai Avatar de Hawk_
    Homme Profil pro
    YouTuber
    Inscrit en
    Septembre 2016
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : YouTuber

    Informations forums :
    Inscription : Septembre 2016
    Messages : 35
    Points : 16
    Points
    16
    Par défaut
    Citation Envoyé par dwlapp Voir le message
    Ok parfait
    Merci pour le temps accordé

  10. #10
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2016
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2016
    Messages : 147
    Points : 81
    Points
    81
    Par défaut
    Pas de soucis

  11. #11
    Membre à l'essai Avatar de Hawk_
    Homme Profil pro
    YouTuber
    Inscrit en
    Septembre 2016
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : YouTuber

    Informations forums :
    Inscription : Septembre 2016
    Messages : 35
    Points : 16
    Points
    16
    Par défaut
    Citation Envoyé par dwlapp Voir le message
    Ok parfait
    Ceci dit tu pourrais peut être m'aider à afficher un message d'erreur.. J'ai un petit soucis à ce niveau la :
    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
     protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
            {
                if (TextBox_num_compte.Text == "" && TextBox_Nom_Partenaire.Text == "" && TextBox_Prenom_Part.Text == "")
                {
                    // Erreur
                    string Error = "";
                else
                {
                    if (TextBox_num_compte.Text == "")
                        e.Command.Parameters["@Numcpt"].Value = '%';
                    else
                        e.Command.Parameters["@Numcpt"].Value = TextBox_num_compte.Text;
     
                    if (TextBox_Nom_Partenaire.Text == "")
                        e.Command.Parameters["@Nom"].Value = '%';
                    else
                        e.Command.Parameters["@Nom"].Value = TextBox_Nom_Partenaire.Text;
     
                    if (TextBox_Prenom_Part.Text == "")
                        e.Command.Parameters["@Prenom"].Value = '%';
                    else
                        e.Command.Parameters["@Prenom"].Value = TextBox_Prenom_Part.Text;
                }
     
            }
     
         }
    Il faut que j'affiche un message d'erreur au niveau du commentaire //Erreur, mais je ne vois pas comment faire.. J'ai beau initialisé une string Erreur et y passer un message, mais celui ci ne s'affiche pas lorsque je fais mon erreur..

  12. #12
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2016
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2016
    Messages : 147
    Points : 81
    Points
    81
    Par défaut
    Tu peux faire un literal

    Coté "html" :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    Coté C# :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
                if (TextBox1.Text.Equals(""))
                {
                    Literal1.Text = "<span>Une erreur est survenue</span>";
                }

  13. #13
    Membre à l'essai Avatar de Hawk_
    Homme Profil pro
    YouTuber
    Inscrit en
    Septembre 2016
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : YouTuber

    Informations forums :
    Inscription : Septembre 2016
    Messages : 35
    Points : 16
    Points
    16
    Par défaut
    Citation Envoyé par dwlapp Voir le message
    Tu peux faire un literal

    Coté "html" :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    Coté C# :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
                if (TextBox1.Text.Equals(""))
                {
                    Literal1.Text = "<span>Une erreur est survenue</span>";
                }

    Je peux le mettre comme ça ?
    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
    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
            {
                <asp:Literal ID="Literal1" runat="server"></asp:Literal>
                if (TextBox_num_compte.Text == "" && TextBox_Nom_Partenaire.Text == "" && TextBox_Prenom_Part.Text == "")
                {
                    Literal1.Text = "<span>Une erreur est survenue</span>
                }
                else
                {
                    if (TextBox_num_compte.Text == "")
                        e.Command.Parameters["@Numcpt"].Value = '%';
                    else
                        e.Command.Parameters["@Numcpt"].Value = TextBox_num_compte.Text;
     
                    if (TextBox_Nom_Partenaire.Text == "")
                        e.Command.Parameters["@Nom"].Value = '%';
                    else
                        e.Command.Parameters["@Nom"].Value = TextBox_Nom_Partenaire.Text;
     
                    if (TextBox_Prenom_Part.Text == "")
                        e.Command.Parameters["@Prenom"].Value = '%';
                    else
                        e.Command.Parameters["@Prenom"].Value = TextBox_Prenom_Part.Text;
                }
            }

  14. #14
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2016
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2016
    Messages : 147
    Points : 81
    Points
    81
    Par défaut
    Ah non !

    Comme ça pour le code C#

    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
            protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
            {
     
                  if (TextBox_num_compte.Text == "" && TextBox_Nom_Partenaire.Text == "" && TextBox_Prenom_Part.Text == "")
                {
                    Literal1.Text = "<span>Une erreur est survenue</span>";
                }
                else
                {
                    if (TextBox_num_compte.Text == "")
                        e.Command.Parameters["@Numcpt"].Value = '%';
                    else
                        e.Command.Parameters["@Numcpt"].Value = TextBox_num_compte.Text;
     
                    if (TextBox_Nom_Partenaire.Text == "")
                        e.Command.Parameters["@Nom"].Value = '%';
                    else
                        e.Command.Parameters["@Nom"].Value = TextBox_Nom_Partenaire.Text;
     
                    if (TextBox_Prenom_Part.Text == "")
                        e.Command.Parameters["@Prenom"].Value = '%';
                    else
                        e.Command.Parameters["@Prenom"].Value = TextBox_Prenom_Part.Text;
                }
            }
    Et ne pas confondre sur la page Html

    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
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="WebApplicationForum.test" %>
     
    <!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>
     
            <asp:Literal ID="Literal1" runat="server"></asp:Literal>
     
        </div>
        </form>
    </body>
    </html>

  15. #15
    Membre à l'essai Avatar de Hawk_
    Homme Profil pro
    YouTuber
    Inscrit en
    Septembre 2016
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : YouTuber

    Informations forums :
    Inscription : Septembre 2016
    Messages : 35
    Points : 16
    Points
    16
    Par défaut
    [QUOTE=dwlapp;8752169]Ah non !

    Comme ça pour le code C#

    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
            protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
            {
     
                  if (TextBox_num_compte.Text == "" && TextBox_Nom_Partenaire.Text == "" && TextBox_Prenom_Part.Text == "")
                {
                    Literal1.Text = "<span>Une erreur est survenue</span>";
                }
                else
                {
                    if (TextBox_num_compte.Text == "")
                        e.Command.Parameters["@Numcpt"].Value = '%';
                    else
                        e.Command.Parameters["@Numcpt"].Value = TextBox_num_compte.Text;
     
                    if (TextBox_Nom_Partenaire.Text == "")
                        e.Command.Parameters["@Nom"].Value = '%';
                    else
                        e.Command.Parameters["@Nom"].Value = TextBox_Nom_Partenaire.Text;
     
                    if (TextBox_Prenom_Part.Text == "")
                        e.Command.Parameters["@Prenom"].Value = '%';
                    else
                        e.Command.Parameters["@Prenom"].Value = TextBox_Prenom_Part.Text;
                }
            }
    Cette méthode ne fonctionne pas.. Rien ne s'affiche lorsque je remplis les 3 paramètres, ou si je ne met rien..

  16. #16
    Membre à l'essai Avatar de Hawk_
    Homme Profil pro
    YouTuber
    Inscrit en
    Septembre 2016
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : YouTuber

    Informations forums :
    Inscription : Septembre 2016
    Messages : 35
    Points : 16
    Points
    16
    Par défaut
    Je me suis pas cassé la tête finalement, j'ai tout simplement mis un label ... Pourquoi chercher compliqué

    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
    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
            {
                if (TextBox_num_compte.Text == "" && TextBox_Nom_Partenaire.Text == "" && TextBox_Prenom_Part.Text == "")
                {
                    // ERROR
                    Label4.Text = "Vous devez saisir un critère de recherche.";
                }
                else
                {
                    Label4.Text = "";
                    if (TextBox_num_compte.Text == "")
                        e.Command.Parameters["@Numcpt"].Value = '%';
    ...
    ...
    ...
    Merci à toi !

  17. #17
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2016
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2016
    Messages : 147
    Points : 81
    Points
    81
    Par défaut
    Oui tu peux aussi faire avec un label, pourtant ce n'est pas trop différent avec un litéral.
    Bon courage

  18. #18
    Membre éprouvé
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    777
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2003
    Messages : 777
    Points : 1 077
    Points
    1 077
    Par défaut
    Et encore mieux de faire le test dans la partie client afin d’éviter un HttpRequest pour rien...

  19. #19
    Membre à l'essai Avatar de Hawk_
    Homme Profil pro
    YouTuber
    Inscrit en
    Septembre 2016
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : YouTuber

    Informations forums :
    Inscription : Septembre 2016
    Messages : 35
    Points : 16
    Points
    16
    Par défaut
    Bonjour,
    Je suis actuellement sur un projet en ASP.net C# et j'ai un petit problème au niveau de ma GridView.. Alors je m'explique.

    J'ai ma page principale "Recherche_Client.aspx", qui comprends 3 TextBox (une pour taper le numéro de compte, et les deux autres pour taper le nom / prénom), l'utilisation est simple, je rentre soit le numéro d'un compte, soit le nom et prénom, une fois appuyer sur le bouton valider, une GridView apparait avec les informations du clients récupéré depuis une BDD MySQLServer (Nom / Prénom / Age / Agence...).

    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Recherche_Client.aspx.cs" Inherits="Reamenagement_Prets.WebForm1" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
        <br />
        <br />
        <img src="search.png" /> Recherche Client :
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Numéro de compte :"></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox_num_compte" runat="server" Width="128px"></asp:TextBox>
        <br />
        <br />
        <img src="ou.png" />
        <br />
        <br />
        <asp:Label ID="Label2" runat="server" Text="Nom du partenaire :"></asp:Label>
        &nbsp;&nbsp;&nbsp; &nbsp;
        <asp:TextBox ID="TextBox_Nom_Partenaire" runat="server" OnTextChanged="TextBox_Nom_Partenaire_TextChanged" Width="128px"></asp:TextBox> <br />
        <asp:Label ID="Label3" runat="server" Text="Prénom du partenaire :"></asp:Label>
        &nbsp;<asp:TextBox ID="TextBox_Prenom_Part" runat="server" Width="127px"></asp:TextBox> <br />
         <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Button ID="Button1" runat="server" Text="Rechercher" OnClick="Button1_Click" />
        <br />
        <br />
        <asp:HyperLinkField Text="View"
            DataNavigateUrlFields="firmaname"
            DataNavigateUrlFormatString="~/Type_de_clients.aspx" />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
            <Columns>
                <asp:BoundField DataField="Nom" HeaderText="Nom" ReadOnly="True" SortExpression="Nom" />
                <asp:BoundField DataField="Age" HeaderText="Age" ReadOnly="True" SortExpression="Age" />
                <asp:BoundField DataField="Type Part." HeaderText="Type Part." ReadOnly="True" SortExpression="Type Part." />
                <asp:BoundField DataField="EDS" HeaderText="EDS" ReadOnly="True" SortExpression="EDS" />
                <asp:BoundField DataField="IDPART" HeaderText="IDPART" ReadOnly="True" SortExpression="IDPART" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ReamPretConnectionString %>" SelectCommand="WF_Recherche_Client" SelectCommandType="StoredProcedure" OnSelecting="SqlDataSource1_Selecting">
            <SelectParameters>
                <asp:Parameter Name="Numcpt" Type="String" />
                <asp:Parameter Name="Nom" Type="String" />
                <asp:Parameter Name="Prenom" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label><br />
    </asp:Content>

    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    namespace Reamenagement_Prets
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
     
            }
     
            protected void TextBox_Nom_Partenaire_TextChanged(object sender, EventArgs e)
            {
     
            }
     
            protected void Button1_Click(object sender, EventArgs e)
            {
                GridView1.DataBind();
            }
     
            protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
            {
                if (TextBox_num_compte.Text == "" && TextBox_Nom_Partenaire.Text == "" && TextBox_Prenom_Part.Text == "")
                {
                    // ERROR
                    Label4.Text = "Vous devez saisir un critère de recherche.";
                }
                else if (TextBox_num_compte.Text != "" && TextBox_Nom_Partenaire.Text != "" && TextBox_Prenom_Part.Text != "")
                {
                    Label4.Text = "Veuillez saisir soit le N° de compte, soit le Nom et Prénom du client.";
                }
                else
                {
                    Label4.Text = "";
                    if (TextBox_num_compte.Text == "")
                        e.Command.Parameters["@Numcpt"].Value = '%';
                    else
                        e.Command.Parameters["@Numcpt"].Value = TextBox_num_compte.Text;
     
                    if (TextBox_Nom_Partenaire.Text == "")
                        e.Command.Parameters["@Nom"].Value = '%';
                    else
                        e.Command.Parameters["@Nom"].Value = TextBox_Nom_Partenaire.Text;
     
                    if (TextBox_Prenom_Part.Text == "")
                        e.Command.Parameters["@Prenom"].Value = '%';
                    else
                        e.Command.Parameters["@Prenom"].Value = TextBox_Prenom_Part.Text;
                }
            }
     
            protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
            {
     
            }
     
        }
    }
    Une fois que les informations du clients s'affiche sur le GridView, il faut que lorsque je clique sur son Nom/Prénom, ça me redirige vers une autre page "Type_de_client.aspx", dans laquelle je vais devoir afficher d'autres renseignement.. Mais je n'ai rien trouvé (oui je me suis documenté) qui fonctionne pour rediriger une page depuis une information GriedView.

    Pouvez-vous m'aider ?

    Merci.

  20. #20
    Membre régulier
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2016
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2016
    Messages : 147
    Points : 81
    Points
    81
    Par défaut
    Salut, peut être ceci je n'ai pas testé :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
            Response.Redirect("TaPage.aspx");
    }

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

Discussions similaires

  1. [AC-2013] Dupliquer des enregistrements en cliquant sur un bouton
    Par rag83 dans le forum IHM
    Réponses: 13
    Dernier message: 30/12/2015, 21h10
  2. Réponses: 2
    Dernier message: 29/04/2015, 13h59
  3. Rajouter des éléments en cliquant sur un bouton
    Par l0c0l0c0 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 12/12/2014, 14h52
  4. Réponses: 6
    Dernier message: 20/04/2007, 12h38
  5. [PHP-JS] ajouter des champ en cliquant sur un bouton?
    Par einsteineuzzz dans le forum Langage
    Réponses: 3
    Dernier message: 29/06/2006, 18h36

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