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 avec pagination


Sujet :

ASP.NET

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    187
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Octobre 2008
    Messages : 187
    Par défaut Gridview avec pagination
    Bonjour,
    Pour ma grid quand j'active AllowPaging="True" et je clique sur le numero de pages pour aller au suivante, j'ai l'exception suivante :
    'System.EventArgs' ne contient pas de définition pour 'NewPageIndex'
    voilà ce que j'ai fait:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridView2.PageIndex = e.NewPageIndex;
            GridView2.DataBind();
        }
    merci de m'avoir lu.

  2. #2
    Membre chevronné
    Profil pro
    Étudiant
    Inscrit en
    Juin 2005
    Messages
    288
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2005
    Messages : 288
    Par défaut
    Essaye en remplacant "EventsArgs" par "GridViewPageEventArgs", tu auras alors accès à la propriété

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 79
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    protected void GridView2_SelectedIndexChanging(object sender, GridViewEventArgs e)
        {
            GridView2.PageIndex = e.NewPageIndex;
            GridView2.DataBind();
        }
    et dans le gridview, tu rajoute cet evenement
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    OnPageIndexChanging="GridView2_SelectedIndexChanging">
    et ça devrait marcher nickel !

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    187
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Octobre 2008
    Messages : 187
    Par défaut
    Merci Djclo et DroP;

    J'ai fais ce que vous m'avez dit et voilà une autre exception:
    Aucune surcharge pour 'GridView2_SelectedIndexChanged' ne correspond au délégué
    je pense que parce que je charge ma grid à l'aide de sql.
    merci encore

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 79
    Par défaut
    c bien GridView2_SelectedIndexChanging et non GridView2_SelectedIndexChanged....
    et c bien aussi GridViewPageEventArgs et non GridViewEventArgs...

    ca decrait allez !

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 79
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    protected void ChangePage_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView2.PageIndex = e.NewPageIndex;
            GridView2.DataBind();
            }

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    187
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Octobre 2008
    Messages : 187
    Par défaut
    merci infiniment djclo
    voilà ce que j'ai fait:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    protected void GridView2_SelectedIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView2.PageIndex = e.NewPageIndex;
            GridView2.DataBind();
        }
    et dans aspx:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      OnPageIndexChanging="GridView2_SelectedIndexChanging"
    mais si je clique sur suivant j'ai plus rien meme ma grid.

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 79
    Par défaut
    comment tu rempli ton gridview ?

  9. #9
    Membre éprouvé
    Inscrit en
    Septembre 2007
    Messages
    1 137
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Septembre 2007
    Messages : 1 137
    Par défaut
    Tu mets le gridview dans un updatePanel et tu ne t'occupe^plus de rien s'il s'agit juste d'afficher des données

  10. #10
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 79
    Par défaut
    alors je vois d ou ca peut venir

  11. #11
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 79
    Par défaut
    envoi ton code aspx stp

  12. #12
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    187
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Octobre 2008
    Messages : 187
    Par défaut
    Voilà mon code 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
    ]<asp:GridView ID="GridView2" Width ="2%" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                BackColor="White" BorderColor="#CCCCCC" BorderWidth="1px" CellPadding="4" CssClass="th"
                DataKeyNames="NUM_INSCRIPTION" Height="1px" PagerStyle-CssClass="note" Style="position: absolute; left: 100px; top: 123px;" AllowPaging="True" OnPageIndexChanging="GridView2_SelectedIndexChanging" PageSize="3" 
    >
                <FooterStyle BackColor="White" ForeColor="#000066" />
                <RowStyle ForeColor="#000066" />
                <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="White" CssClass="note" ForeColor="#000066" HorizontalAlign="Left" />
                <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
    <Columns>                <asp:TemplateField HeaderText="aaa">
                        <ItemStyle CssClass="td00" />
                        <ItemTemplate>
                            <asp:Label ID="lblUserID1" runat="server" Text='<%# Eval("NUm") %>'></asp:Label>
                            <itemstyle cssclass="td00" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="aa">
                        <ItemStyle CssClass="td01" />
                        <ItemTemplate>
                            <asp:Label ID="lblUserID2" runat="server" Text='<%# Eval("NOM") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="ccc">
                        <ItemTemplate>
                            <asp:Label ID="Label13" runat="server" Font-Bold="true" Text='<%# Eval("141") %>'></asp:Label></td>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="abb">
                        <ItemTemplate>
                            <asp:Label ID="Label14" runat="server" Font-Bold="true" Text='<%# Eval("142") %>'></asp:Label></td>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="fff">
                        <ItemTemplate>
                            <asp:Label ID="Label14" runat="server" Font-Bold="true" Text='<%# Eval("143") %>'></asp:Label></td>
                        </ItemTemplate>
                    </asp:TemplateField>
                                             <asp:Label ID="moo" runat="server" Text='<%# Eval("m4") %>' Visible='<%# !(bool) IsInEditMode %>'></asp:Label>
                                <asp:TextBox ID="mo4" runat="server" Text='<%# Eval("m4") %>' Visible='<%# IsInEditMode %>'></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="V4">
                        <ItemTemplate>
                            <asp:Label ID="v4" runat="server" Text='<%# Eval("v4") %>' Visible='<%# !(bool) IsInEditMode %>'></asp:Label>
                            <asp:TextBox ID="validt4" runat="server" Text='<%# Eval("v4") %>' Visible='<%# IsInEditMode %>'></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <RowStyle ForeColor="#000066" />
                <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="White" CssClass="note" ForeColor="#000066" HorizontalAlign="Left" />
                <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
            </asp:GridView>

  13. #13
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    187
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Octobre 2008
    Messages : 187
    Par défaut
    Cde behind:
    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
     
     
    private void BindData()
        {
            SqlConnection myConnection = new SqlConnection(ConnectionString);
     
          String strSQL = "ma reuqete est trés longue ";
     
     
            SqlDataAdapter ad = new SqlDataAdapter(strSQL, myConnection);
            DataSet ds = new DataSet();
            ad.Fill(ds);
            GridView1.DataSource = ds;
            //isEditMode = true;
            GridView1.DataBind();
            //GridView1.Attributes.Add("style", "table-layout:fixed");
     
     
        }
     
        private string ConnectionString
        {
            get
            {
                string connectionString = (@"Data Source=.\SQLEXPRESS;UID=sa;Password=xxxxInitial Catalog=BD");
     
                // string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                return connectionString;
            }
        }  protected void Button3_Click(object sender, EventArgs e)
        {
            BindData();}

  14. #14
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 79
    Par défaut
    rajoute binddata(); en desous de gridview2.databind();
    ca dervrait marcher !

  15. #15
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 79
    Par défaut
    rajoute binddata(); en desous de gridview2.databind();
    ca dervrait marcher !

  16. #16
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    187
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Octobre 2008
    Messages : 187
    Par défaut
    non ça marche pas !!!
    Merci infiniment Djclo;

  17. #17
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 79
    Par défaut
    protected void GridView2_SelectedIndexChanging(object sender, GridViewPageEventArgs e)
    {
    GridView2.PageIndex = e.NewPageIndex;
    GridView2.DataBind();

    }

  18. #18
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2008
    Messages : 79
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    protected void GridView2_SelectedIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView2.PageIndex = e.NewPageIndex;
            GridView2.DataBind();
            binddata();
        }
    et dans ton page _load tu fais :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
             binddata();
            }
        }
    et ca va marcher !
    @ plus

  19. #19
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    187
    Détails du profil
    Informations personnelles :
    Localisation : Maroc

    Informations forums :
    Inscription : Octobre 2008
    Messages : 187
    Par défaut
    Enfin ça marche
    j'ai oublié
    GridView2.Visible = true;
    je vous remercie beaucoup beaucoup Djclo

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

Discussions similaires

  1. exception avec pagination sur gridview
    Par intissar_g dans le forum ASP.NET
    Réponses: 16
    Dernier message: 27/07/2011, 17h31
  2. GridView avec pagination et tri
    Par dany13 dans le forum VB.NET
    Réponses: 2
    Dernier message: 17/03/2010, 08h27
  3. [CSV] Affichage d'un fichier csv avec pagination
    Par arnoweb dans le forum Langage
    Réponses: 4
    Dernier message: 26/07/2006, 15h13
  4. Réponses: 3
    Dernier message: 26/07/2006, 10h18
  5. Réponses: 2
    Dernier message: 20/06/2006, 16h32

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