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, RowUpdating -> OutOfRange


Sujet :

ASP.NET

  1. #1
    Membre averti
    Inscrit en
    Avril 2008
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 35
    Par défaut GridView, RowUpdating -> OutOfRange
    Bonjour,

    J'ai une GV qui est chargée à partir d'une BDD.
    Lorsque je clique sur le bouton Edit d'une ligne de mon GV, j'arrive à modifier les champs mais lorsque je clique sur Update, j'ai une erreur OutOfRange sur la ligne int myID = Convert.ToInt32(gv_db.DataKeys[e.RowIndex].Value);

    Code ASP

    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
     
    <asp:GridView ID="gv_db" runat="server" AutoGenerateColumns="False" DataKeyNames="id" OnRowEditing="gv_db_RowEditing" OnRowUpdating="gv_db_RowUpdating" OnRowCancelingEdit="gv_db_RowCanceling" CssClass="gridView" HeaderStyle-CssClass="header" RowStyle-CssClass="rows" HorizontalAlign="Left">
                        <HeaderStyle CssClass="header"></HeaderStyle>
                        <RowStyle CssClass="rows" Wrap="False"></RowStyle>
                        <Columns>
                        <%--<asp:CommandField ShowEditButton="True" />--%>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:LinkButton ID="LkB1" runat="server" CommandName="Edit">Edit</asp:LinkButton>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:LinkButton ID="LB2" runat="server" CommandName="Update">Update</asp:LinkButton>
                                    <asp:LinkButton ID="LB3" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
                                </EditItemTemplate>
                            </asp:TemplateField>
     
                            <asp:TemplateField HeaderText="id2">
                                <ItemTemplate>
                                    <asp:Label ID="lbl_id2" runat="server" Text='<%# Eval("id2") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="tb_id2" runat="server" Text='<%# Eval("id2") %>'></asp:TextBox>
                                </EditItemTemplate>
                            </asp:TemplateField>
     
                            <asp:TemplateField HeaderText="BU">
                                <ItemTemplate>
                                    <asp:Label ID="lbl_BU" runat="server" Text='<%# Eval("BU") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="tb_BU" runat="server" Text='<%# Eval("BU") %>'></asp:TextBox>
                                </EditItemTemplate>
                            </asp:TemplateField>  
    ...
    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
    26
    27
    28
    29
    30
    protected void gv_db_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            // find student id of edit row
            //string id = gv_db.DataKeys[e.RowIndex].Value.ToString();
            int myID = Convert.ToInt32(gv_db.DataKeys[e.RowIndex].Value);
            // find updated values for update
    
            TextBox id2 = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_id2");
            TextBox BU = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_BU");
            TextBox Country = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_Country");
            TextBox Alpha2 = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_Alpha2");
            TextBox Digital = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_Digital");
            TextBox City = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_City");
            TextBox State = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_State");
            TextBox cp = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_cp");
            TextBox UPN = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_UPN");
            TextBox displayName = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_displayName");
            TextBox o365 = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_o365");
            TextBox vpn = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_vpn");
            TextBox internet = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_internet");
            TextBox OU = (TextBox)gv_db.Rows[e.RowIndex].FindControl("txt_OU");
    
    
            DB.UpdateDBRef("SQL_UPDATE_1", myID, id2.Text, BU.Text, Country.Text, Alpha2.Text, Digital.Text, City.Text, State.Text, cp.Text, UPN.Text, displayName.Text, o365.Text, vpn.Text, internet.Text, OU.Text);
    
            gv_db.EditIndex = -1;
            gv_db.DataSource = DB.GetDBRef();
            gv_db.DataBind();
        }
    Une idée ?

  2. #2
    Membre averti
    Inscrit en
    Avril 2008
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 35
    Par défaut
    une âme charitable saurait-elle mettre en lumière l'erreur qui ne veut pas m’apparaître ?

  3. #3
    Membre averti
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2016
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : Haïti

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juin 2016
    Messages : 29
    Par défaut
    Essaie d'ajouter un toString a ta value.

    Essaie avec ce code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    int myID = Convert.ToInt32(gv_db.DataKeys[e.RowIndex].Value.toString())

Discussions similaires

  1. GridView RowUpdating FindControl toujours null
    Par Arnaud13 dans le forum ASP.NET
    Réponses: 1
    Dernier message: 03/07/2014, 17h45
  2. Réponses: 21
    Dernier message: 30/12/2010, 13h33
  3. [2.0] GridView RowUpdating sans source sql
    Par frechy dans le forum ASP.NET
    Réponses: 3
    Dernier message: 12/06/2009, 16h25
  4. GridView RowUpdating problème
    Par duffman dans le forum ASP.NET
    Réponses: 2
    Dernier message: 29/04/2009, 12h07
  5. Evenement RowUpdating avec GridView
    Par Jérôme Lambert dans le forum ASP.NET
    Réponses: 6
    Dernier message: 17/08/2007, 10h47

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