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 :

GridView evènement clic


Sujet :

ASP.NET

  1. #1
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    196
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2012
    Messages : 196
    Points : 197
    Points
    197
    Par défaut GridView evènement clic
    Bonjour,
    Je cherche depuis un certain temps des informations pour gérer l'évènement clic dans un gridview en ASP.NET C#.

    J'ai trouvé certaines informations mais il m'en manque.
    Voici mon 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
    	private void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowIndex >= 0)
                {
                    for (int cellIndex = 1; cellIndex < e.Row.Cells.Count; cellIndex++)
                    {
                        e.Row.Cells[cellIndex].Attributes.Add("onmouseover", string.Format("this.style.cursor = 'hand'"));
                        e.Row.Cells[cellIndex].ToolTip = "test";
                        e.Row.Cells[cellIndex].Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.gridview1, "Select$" + e.Row.DataItemIndex, true);
                    }
                }
            }
     
            private void gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                String txt = this.gridview1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[???].Text;
            }
    Ce qui me manque :
    1) dans l'évènement RowCommand, comment avoir le numéro de la colonne?
    2) comment gérer l'évènement clic sur une entête d'une colonne?
    3) je souhaiterais exécuter une méthode C# lors du clic

    Merci d'avance pour votre aide

  2. #2
    Candidat au Club
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Août 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Argentine

    Informations professionnelles :
    Activité : Chargé d'affaire
    Secteur : Bâtiment

    Informations forums :
    Inscription : Août 2012
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {




    if (e.CommandName == "id") {

    int index;
    string valor;

    index = int.Parse(e.CommandArgument.ToString());
    valor = GridView1.DataKeys[index].Value.ToString();
    }
    }



  3. #3
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    196
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2012
    Messages : 196
    Points : 197
    Points
    197
    Par défaut
    merci pour ta réponse mais il me faut le numéro de la colonne dans l'évènement RowCommand car ce que j'ai mis n'est que temporaire.
    Je souhaite mettre l'appel d'une méthode qui prend pour argument le numéro de la ligne et de la colonne pour récupérer les infos qui se trouvent dans une datatable.

  4. #4
    Membre du Club
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Février 2006
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 38
    Points : 53
    Points
    53
    Par défaut
    Salut,
    La clé tu peux la mettre dans ton commandargument car c'est quoi l'intérêt d'avoir ton numéro de ligne? Si tu fais un trie, les numéro de lignes seront changé.

    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:GridView ID="gv" AutoGenerateColumns="False" DataKeyNames="ID" runat="server"
     AllowPaging="True" AllowSorting="True"
            CellPadding="0" OnRowDataBound="gv_OnRowDataBound" ForeColor="#333333" GridLines="Vertical"
            PageSize="5" OnRowCommand="gv_OnRowCommand" BorderColor="#507CD1" BorderWidth="1px">
            <Columns>
                    <ItemTemplate>
                        <asp:ImageButton SkinID="MaillingModifier" ID="lkMod" ToolTip="Modifier" CommandArgument='<%#Eval("ID")%>'
                            ImageAlign="Middle" CommandName="Edit" runat="server" />&nbsp;<asp:ImageButton SkinID="MaillingDetail"
                                ID="lkDetail" ToolTip="Détails" CommandArgument='<%#Eval("ID")%>' ImageAlign="Middle"
                                CommandName="Details" runat="server" />&nbsp;<asp:ImageButton SkinID="MaillingSupprimer"
                                    CommandName="Delete" ID="lkDel" runat="server" ToolTip="Supprimer" OnClientClick='return message(this.name);'
                                    CommandArgument='<%#Eval("ID")%>' ImageAlign="Middle" />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center" />
                </asp:TemplateField>

    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
     
    protected void gv_OnRowCommand(object sender, GridViewCommandEventArgs e)
            {
                switch (e.CommandName)
                {
                   case "Edit":
                        Response.Redirect("Traitement.aspx?Current=E&ID=" + e.CommandArgument.ToString());
                        break;
     
                    case "Filtre":
                        Session["txtsearchname"] = "%";
                        Session["txtsearchdossier"] = "%";
                        break;
     
                    case "Sort":
                        switch (e.CommandArgument.ToString())
    	                {
    		                case "DOSSIER":
                                ascdesc.Value = "Img_1";
                                break;
                            case "NAME":
                                ascdesc.Value = "Img_2";
                                break;
    	                }                   
     
                        break;
                }
            }

  5. #5
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    196
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2012
    Messages : 196
    Points : 197
    Points
    197
    Par défaut
    bon, il faut que je donne plus d'explications.
    Je fais un tableau dont les lignes et les colonnes sont placés dans un ordre défini par l'utilisateur.
    Un clic sur l'entête d'une ligne ou d'une colonne permet de modifier le texte de l'entête et/ou son placement parmi les autres lignes/colonnes.
    Un clic sur une cellule permet de modifier son texte, un commentaire en tooltip et son image de fond.
    Ne sachant pas trop comment m'y prendre, j'ai commencé 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
    26
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    DataTable dt = new DataTable();
                    foreach (Colonne c in colonnes.Values)
                    {
                        dt.Columns.Add(c.texte);
                    }
                    foreach (Ligne li in lignes.Values)
                    {
                        DataRow dr = dt.NewRow();
                        dr[0] = li.texte;
                        for (int k = 1; k < nbcolonne; k++)
                        {
                            TemplateField tf = new TemplateField();
                            tf.ItemTemplate = new Services.MonTemplate("label" + k, "Label");
                            tf.HeaderText = li.cellule(k, li).texte;
                            dr[k] = tf;
                        }
                        dt.Rows.Add(dr);
                    }
                    dg1.DataSource = dt;
                }
                dg1.DataBind();
            }
    Mais en plus, je souhaite lors du clic pour les modifications, afficher dans un panel ou un autre fenêtre les informations actuelles de la cellule, entête de la ligne/colonne avant de les modifier.
    Donc pour ça, par exemple, j'ai besoin du numéro de ligne et de colonne de la cellule pour récupérer les informations

Discussions similaires

  1. Réponses: 1
    Dernier message: 23/09/2009, 13h11
  2. Gridview : recupération clic ImageButton
    Par snopims dans le forum ASP.NET
    Réponses: 4
    Dernier message: 09/10/2007, 14h17
  3. Réponses: 15
    Dernier message: 13/03/2007, 17h25
  4. Evènement clic droit
    Par lito74 dans le forum Access
    Réponses: 4
    Dernier message: 13/12/2006, 17h06
  5. Evènements Clic et Double Clic dans un contrôle
    Par jeportal dans le forum Access
    Réponses: 16
    Dernier message: 10/01/2006, 11h37

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