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 :

Problème avec Gridview


Sujet :

ASP.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    197
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Septembre 2005
    Messages : 197
    Par défaut Problème avec Gridview
    .Net 2.0/3.5 sur Visual Studio 2010 - Windows Vista

    Bonjour,

    J'ai un gridview qui contient un bouton de type "select" (je l'ai nommé "Link"). Lorsque je click sur Link, je suis incapable d'obtenir le contenu d'une cellule de la rangée sélectionnée. J'ai pris le code directement sur MSDN et ca ne fonctionne pas. J'ai essayé beaucoup d'autres trucs mais sans succès.

    L'évènement:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    protected void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
        {
            GridViewRow row = GridView1.SelectedRow;
            string message = "You selected " + row.Cells[2].Text + ".";
        }
    est lancé, l'objet row est bien actualisé mais le row.Cells[2].Text est vide!

    .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
    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
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewInsertEditUpdateDelete.aspx.cs" Inherits="GridViewInsertEditUpdateDelete" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
     
     
        <form id="form1" runat="server">
     
            <br />
            <asp:Label ID="Label9" runat="server" Text="Project"></asp:Label>
            : &nbsp;
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <br />
     
        <div >
        <br />
     
     
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <div>
                <asp:Panel ID="Panel1" runat="server" Width="989px" Wrap="true">
                 <asp:GridView ID="GridView1"   runat="server" AutoGenerateColumns="False" DataKeyNames="softwareRequirementId" 
            OnRowCancelingEdit="GridView1_RowCancelingEdit" 
            OnRowDataBound="GridView1_RowDataBound" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" 
            OnRowCommand="GridView1_RowCommand" 
                Onselectedindexchanged="GridView1_SelectedIndexChanged" Onselectedindexchanging="GridView1_SelectedIndexChanging" 
            ShowFooter="True" OnRowDeleting="GridView1_RowDeleting" 
            EnableModelValidation="True" Width="100%"> 
     
            <Columns> 
     
     
     
              <asp:TemplateField HeaderText="Id"  SortExpression="softwareRequirementId"> <EditItemTemplate> 
              <asp:TextBox ID="txtsoftwareRequirementId"  runat="server"  Text='<%# Eval("softwareRequirementId") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <FooterTemplate> 
              <asp:TextBox ID="txtNewsoftwareRequirementId" runat="server"></asp:TextBox> </FooterTemplate> 
            <ItemTemplate> 
              <asp:Label ID="Label2" runat="server" Text='<%# Bind("softwareRequirementId") %>'></asp:Label> 
            </ItemTemplate> 
                <ControlStyle BackColor="GhostWhite" Font-Bold="True" Width="100px" />
                  <FooterStyle Width="100px" />
                <HeaderStyle BackColor="Beige" Width="100px" />
                  <ItemStyle Width="100px" ForeColor="#0099FF" />
            </asp:TemplateField> 
     
     
            <asp:TemplateField HeaderText="Project"  SortExpression="projectId"> <EditItemTemplate> 
              <asp:TextBox ID="txtprojectId" columns="1"  runat="server" Text='<%# Eval("projectId") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <FooterTemplate> 
              <asp:TextBox ID="txtNewprojectId" runat="server"></asp:TextBox> </FooterTemplate> 
            <ItemTemplate> 
              <asp:Label ID="Label3" runat="server" Text='<%# Bind("projectId") %>'></asp:Label> 
            </ItemTemplate> 
                <ControlStyle BackColor="GhostWhite" Font-Bold="True" Width="100px" />
                <HeaderStyle BackColor="Beige" Width="100px" />
            </asp:TemplateField> 
     
            <%--<asp:TemplateField HeaderText="Elevate" ShowHeader="True"> 
                <EditItemTemplate> 
                   <asp:LinkButton ID="LinkElevate" runat="server" CausesValidation="True" CommandName="elevate" Text="Elevate"></asp:LinkButton> 
                </EditItemTemplate>
                <HeaderStyle BackColor="Tan" />
     
            </asp:TemplateField> --%>
     
            <asp:ButtonField  ButtonType="Button" CommandName="elevate" Text="Button" />
     
     
     
            <asp:TemplateField HeaderText="Section" SortExpression="section"> <EditItemTemplate> 
              <asp:TextBox ID="txtsection" columns="1"  runat="server" Text='<%# Eval("section") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <FooterTemplate> 
              <asp:TextBox ID="txtNewsection" runat="server"></asp:TextBox> </FooterTemplate> 
            <ItemTemplate> 
              <asp:Label ID="Label4" runat="server" Text='<%# Bind("section") %>'></asp:Label> 
            </ItemTemplate> 
                <HeaderStyle BackColor="Tan" />
            </asp:TemplateField> 
     
     
     
            <asp:TemplateField HeaderText="rowNumber"> 
            <EditItemTemplate> 
              <asp:TextBox ID="txtrowNumber" runat="server" Text='<%# Bind("rowNumber") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <FooterTemplate> 
              <asp:TextBox ID="txtNewrowNumber" runat="server" ></asp:TextBox> 
            </FooterTemplate> 
            <ItemTemplate> 
              <asp:Label ID="Label5" runat="server" Text='<%# Bind("rowNumber") %>'></asp:Label> 
            </ItemTemplate> 
                <HeaderStyle BackColor="Tan" />
            </asp:TemplateField> 
     
     
     
            <asp:TemplateField HeaderText="softwareRequirement" > 
            <EditItemTemplate> 
              <asp:TextBox ID="txtsoftwareRequirement" TextMode="multiline" columns="50" runat="server" Text='<%# Bind("softwareRequirement") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <FooterTemplate> 
              <asp:TextBox ID="txtNewsoftwareRequirement" runat="server" ></asp:TextBox> 
            </FooterTemplate> 
            <ItemTemplate> 
              <asp:Label ID="Label6" runat="server" Text='<%# Bind("softwareRequirement") %>'></asp:Label> 
            </ItemTemplate> 
                <HeaderStyle BackColor="Tan" />
            </asp:TemplateField> 
     
     
     
            <asp:TemplateField HeaderText="isTraced" SortExpression="isTraced"> 
            <EditItemTemplate> 
              <asp:TextBox ID="txtisTraced" runat="server" Text='<%# Bind("isTraced") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <FooterTemplate> 
              <asp:TextBox ID="txtNewisTraced" runat="server" ></asp:TextBox> 
            </FooterTemplate> 
            <ItemTemplate> 
              <asp:Label ID="Label7" runat="server" Text='<%# Bind("isTraced") %>'></asp:Label> 
            </ItemTemplate> 
                <HeaderStyle BackColor="Tan" />
            </asp:TemplateField> 
     
     
     
     
            <asp:TemplateField HeaderText="image" > 
            <EditItemTemplate> 
              <asp:TextBox ID="txtimage" runat="server" Text='<%# Bind("image") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <FooterTemplate> 
              <asp:TextBox ID="txtNewimage" runat="server" ></asp:TextBox> 
            </FooterTemplate> 
            <ItemTemplate> 
              <asp:Label ID="Label8" runat="server" Text='<%# Bind("image") %>'></asp:Label> 
            </ItemTemplate> 
                <HeaderStyle BackColor="Tan" />
            </asp:TemplateField> 
     
     
     
     
            <asp:TemplateField HeaderText="Edit" ShowHeader="False"> 
                <EditItemTemplate> 
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> 
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> 
     
     
                </EditItemTemplate> 
     
                <FooterTemplate> 
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="AddNew" Text="Add New"></asp:LinkButton> 
                </FooterTemplate> 
     
                <ItemTemplate> 
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton> 
     
                </ItemTemplate> 
     
                <HeaderStyle BackColor="Tan" />
     
            </asp:TemplateField> 
     
     
            <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" >
                <HeaderStyle BackColor="Tan" />
            </asp:CommandField> 
     
     
     
                <asp:ButtonField CommandName="Select" HeaderText="Link" ShowHeader="True" 
                    Text="Link" />
     
     
     
            </Columns> 
    </asp:GridView> 
     
                </asp:Panel>
            </div>
        </form>
    </body>
    </html>

    .aspx.cs
    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
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
     
     
    public partial class GridViewInsertEditUpdateDelete : System.Web.UI.Page
    {
        private string projectId;
        SoftwareRequirementsCls softwareRequirements = new SoftwareRequirementsCls();
        ProjectCls projects = new ProjectCls();
     
     
        protected void Page_Load(object sender, EventArgs e)
        {
            UrlParameterPasser urlWrapper = new UrlParameterPasser();
            projectId = Request.QueryString["projectId"];
     
            if (!IsPostBack)
            {
     
                DataTable dtProjects = projects.Fetch(projectId);
     
                foreach (DataRow row in dtProjects.Rows)
                {
                    TextBox2.Text = row["projectName"].ToString();   
                }
     
                FillSoftwareRequirementsInGrid();
            }
     
     
     
        }
     
        private void FillSoftwareRequirementsInGrid()
        {
            DataTable dtSoftwareRequirements = softwareRequirements.Fetch(projectId);
     
            if (dtSoftwareRequirements.Rows.Count > 0)
            {
                GridView1.DataSource = dtSoftwareRequirements;
                GridView1.DataBind();
            }
            else
            {
                dtSoftwareRequirements.Rows.Add(dtSoftwareRequirements.NewRow());
                GridView1.DataSource = dtSoftwareRequirements;
                GridView1.DataBind();
     
                int TotalColumns = GridView1.Rows[0].Cells.Count;
                GridView1.Rows[0].Cells.Clear();
                GridView1.Rows[0].Cells.Add(new TableCell());
                GridView1.Rows[0].Cells[0].ColumnSpan = TotalColumns;
                GridView1.Rows[0].Cells[0].Text = "No Record Found";
            }
        }
     
     
     
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("AddNew"))
            {
                TextBox txtNewsoftwareRequirementId = (TextBox)GridView1.FooterRow.FindControl("txtNewsoftwareRequirementId");
                TextBox txtNewprojectId = (TextBox)GridView1.FooterRow.FindControl("txtNewprojectId");
                TextBox txtNewsection = (TextBox)GridView1.FooterRow.FindControl("txtNewsection");
                //DropDownList cmbNewsection = (DropDownList)GridView1.FooterRow.FindControl("cmbNewsection");
                TextBox txtNewrowNumber = (TextBox)GridView1.FooterRow.FindControl("txtNewrowNumber");
                TextBox txtNewsoftwareRequirement = (TextBox)GridView1.FooterRow.FindControl("txtNewsoftwareRequirement");
                TextBox txtNewisTraced = (TextBox)GridView1.FooterRow.FindControl("txtNewisTraced");
                TextBox txtNewimage = (TextBox)GridView1.FooterRow.FindControl("txtNewimage");
     
                softwareRequirements.Insert(projectId, txtNewsection.Text, txtNewrowNumber.Text, txtNewsoftwareRequirement.Text, txtNewisTraced.Text, txtNewimage.Text);
                FillSoftwareRequirementsInGrid();
            }
     
            if (e.CommandName.Equals("Edit"))
            {
     
     
            }
     
            if (e.CommandName.Equals("Link"))
            {
     
     
     
                //UrlParameterPasser urlWrapper = new UrlParameterPasser("linkToSysReq.aspx");
     
                //urlWrapper["softwareRequirementId"] = GridView1.Rows[index].Cells[0].Text;
                //urlWrapper["projectId"] = GridView1.Rows[index].Cells[1].Text;
                //urlWrapper.PassParameters();     
     
            }
            else if (e.CommandName.Equals("elevate"))
            {
                //int index = Convert.ToInt32(e.CommandArgument);
     
                //GridView1.Rows[index].Cells[2].Text = "4";
     
                //string a = GridView1.Rows[index].Cells[2].Text;
     
                //int softwareRequirementId = Convert.ToInt32(GridView1.Rows[index].Cells[3].Text);
     
                 //GridViewRow row = GridView1.SelectedRow;
     
                 //int a = row.RowIndex;
     
                //string sec = txtNewsection.Text;
     
     
                //int softwareRequirementId = Convert.ToInt32(GridView1.Cells[0].Text);
                //int a = Convert.ToInt32(GridView1.Rows[index].Cells[3].Text);
                //int a++;
                //GridView1.Rows[index].Cells[1].Text = a.ToString();
            }
     
     
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
     
                    //    DropDownList cmbType = (DropDownList)e.Row.FindControl("cmbsection");
     
                //if (cmbType != null)
                //{
                //    try
                //    {
                //        cmbType.DataSource = softwareRequirements.FetchSectionType();
                //        cmbType.DataBind();
                //        cmbType.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[0].ToString();
                //    }
                //    catch (Exception err)
                //    {
                //        //TextBox1.Text = "Error reading list of names. ";
                //        //TextBox1.Text += err.Message;
                //    }
                //}
     
     
     
     
     
     
     
            }
     
            //if (e.Row.RowType == DataControlRowType.Footer)
            //{
            //    //DropDownList txtNewisTraced = (DropDownList)e.Row.FindControl("cmbNewsection");
            //    //txtNewisTraced.DataSource = softwareRequirements.FetchSectionType();
            //    //txtNewisTraced.DataBind();
            //}
        }
        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            FillSoftwareRequirementsInGrid();
        }
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            softwareRequirements.Delete(Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString()));
            FillSoftwareRequirementsInGrid();
        }
        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            FillSoftwareRequirementsInGrid();
     
     
     
        }
     
        protected void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
        {
     
     
            GridViewRow row = GridView1.SelectedRow;
            string message = "You selected " + row.Cells[2].Text + ".";
     
     
        }
     
        protected void GridView1_SelectedIndexChanging(Object sender, GridViewSelectEventArgs e)
        {
     
            // Get the currently selected row. Because the SelectedIndexChanging event
            // occurs before the select operation in the GridView control, the
            // SelectedRow property cannot be used. Instead, use the Rows collection
            // and the NewSelectedIndex property of the e argument passed to this 
            // event handler.
            GridViewRow row = GridView1.Rows[e.NewSelectedIndex];
     
            // You can cancel the select operation by using the Cancel
            // property. For this example, if the user selects a customer with 
            // the ID "ANATR", the select operation is canceled and an error message
            // is displayed.
            if (row.Cells[1].Text == "ANATR")
            {
     
                e.Cancel = true;
                TextBox1.Text = "You cannot select " + row.Cells[2].Text + ".";
     
            }
     
        }
     
     
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            TextBox txtsoftwareRequirementId = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtsoftwareRequirementId");
            TextBox txtprojectId = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtprojectId");
            TextBox txtsection = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtsection");
            //DropDownList cmbsection = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("cmbsection");
            TextBox txtrowNumber = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtrowNumber");
            TextBox txtsoftwareRequirement = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtsoftwareRequirement");
            TextBox txtisTraced = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtisTraced");
            TextBox txtimage = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtimage");
     
            softwareRequirements.Update(Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString()), projectId, txtsection.Text, txtrowNumber.Text, txtsoftwareRequirement.Text, txtisTraced.Text, txtimage.Text);
            GridView1.EditIndex = -1;
            FillSoftwareRequirementsInGrid();
        }
     
     
        protected void Button1_Click(object sender, EventArgs e)
        {
     
            HtmlDocument doc = new HtmlDocument("1");
            doc.printDocument();
     
        }
    }

  2. #2
    Membre Expert
    Avatar de Nicolas Esprit
    Homme Profil pro
    Consultant en technologies
    Inscrit en
    Février 2010
    Messages
    1 467
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Consultant en technologies
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2010
    Messages : 1 467
    Par défaut
    Bonjour,

    Ta cellule correspond à un Template donc contient plusieurs contrôles. Deux solutions : appeller un FindControl (voire FindControl récursif) à partir de ta cellule pour trouver le contrôle désiré. Ou bien simplement, mais c'est moins conseillé, utiliser l'index du contrôle désiré, genre : row.Cells[2][1] .Text.

    En espérant t'avoir aidé.

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    197
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Septembre 2005
    Messages : 197
    Par défaut
    Pour ta première recommendation, c'est exactement ce que j'utilise (voir mon code en haut, 2e ligne).

    Pour ta 2e, je l'ai utilisé mais l'objet récupéré est vide aussi.

    J'ai constaté que plusieurs personnes avaient le même problème sur le Web mais je n'ai pas encore vu la solution. Serait-ce un problème avec .Net?

  4. #4
    Membre Expert
    Avatar de Nicolas Esprit
    Homme Profil pro
    Consultant en technologies
    Inscrit en
    Février 2010
    Messages
    1 467
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Consultant en technologies
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2010
    Messages : 1 467
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    protected void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
        {
            GridViewRow row = GridView1.SelectedRow;
            string message = "You selected " + row.Cells[2].Text + ".";
        }
    Je ne vois pas de FindControl ici. De plus, Cells[2] correspond à la troisième colonne de ta GridView, c'est à dire un bouton...

    Donc un FindControl récursif devrait suffire. Au pire, tu peux toujours mettre un breakpoint et regarder avec le débuggeur où se situe le contrôle que tu veux (quelle cellule).

    Et non ce n'est pas un problème .NET

    En espérant t'avoir aidé.

  5. #5
    Membre du Club
    Inscrit en
    Avril 2008
    Messages
    8
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations forums :
    Inscription : Avril 2008
    Messages : 8
    Par défaut methode FindControl
    Salut,

    Essayer le code suivant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    protected void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
        {
            GridViewRow row = GridView1.SelectedRow;
         Button message = "You selected a " + ((Button)row.FindControl("Link")).Text + ".";
        }

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    197
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Septembre 2005
    Messages : 197
    Par défaut Nicholas,
    L'exemple avev FindControl() n'est pas indiqué dans ce thread mais voici ce que j'ai dans mon application et ca ne fonctionne pas non plus.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Control myControl = GridView1.Rows[e.NewSelectedIndex].FinControl("txtSoftwareRequirementid");
    Notez que que e.NewSelectedIndex donne le bon index mais que l'objet Control récupéré est Null.


    Pour la cellule #3 donc tu parlais, je n'ai plus de bouton, seulement un textbox. De toute façon j'ai essayé toute les cellules..sans succès.

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    197
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Septembre 2005
    Messages : 197
    Par défaut souloff
    Ton code ne compile pas.

Discussions similaires

  1. [vb.net]problème avec gridview
    Par bouchra19 dans le forum ASP.NET
    Réponses: 3
    Dernier message: 09/07/2012, 14h13
  2. Problème avec GridView
    Par OLman135 dans le forum ASP.NET
    Réponses: 2
    Dernier message: 29/09/2011, 13h50
  3. Problème avec GridView
    Par ezsoft dans le forum ASP.NET
    Réponses: 8
    Dernier message: 11/05/2009, 18h52
  4. Problème avec gridview
    Par hugo7 dans le forum ASP.NET
    Réponses: 4
    Dernier message: 26/11/2008, 14h45
  5. Problème avec Gridview SelectedRow
    Par yass dans le forum ASP.NET
    Réponses: 2
    Dernier message: 09/07/2008, 11h55

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