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 :

pagertemplate et trois petits points


Sujet :

ASP.NET

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    145
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 145
    Par défaut pagertemplate et trois petits points
    Bonjour a tous ! alors voila j'utilise un super controle pour le pager template que l'on peut trouver ici http://www.codeproject.com/KB/webfor...px?msg=2732333

    Maintenant le probleme, c'est que quand j'ai beaucoup beaucoup de resultats j'aimerai ajouter une petite fonction qui me coupe les numeros de page par trois petits points un peu comme dans le pagertemplate d'origine...
    Si vous avez une idee sur la maniere dont je peux proceder je vous en remercie !

  2. #2
    Expert confirmé
    Avatar de Immobilis
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2004
    Messages
    6 559
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 559
    Par défaut
    Salut,

    Il faudrait les sources du controle et modifier le code qui agit au moment de la création des numéros de pages.

    A+
    "Winter is coming" (ma nouvelle page d'accueil)

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    145
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 145
    Par défaut
    Bon ben j'ai trouve une autre maniere ... J'ai poste un peu trop vite a dire vrai !
    En tout cas merci beaucoup !

    Pour ceux qui veulent la reponse, c'est tout simple il y a une variable qui permet de donner le nombre maximum de page.
    A+

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    145
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 145
    Par défaut
    Bon alors, finalement ca ne va pas.
    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
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
     
    namespace GlobalWeb.Controls
    {
        /// <summary>
        /// Summary description for FullGridPager
        /// FullGridPager is a very nice and complete custom pager to use inside a GridView's PagerTemplate.
        /// Images files:
        ///     Images/firstpage.gif
        ///     Images/prevpage.gif
        ///     Images/nextpage.gif
        ///     Images/lastpage.gif
        /// CSS:
        ///     .pagerOuterTable    : the style of the html table.
        ///     .pageCounter        : the style of the first table cell "Page 1 of N".
        ///     .pageFirstLast      : the style of the First and Last cells.
        ///     .pagerLink          : the style of the page number links.
        ///     .pagePrevNextNumber : the style of the Previous, Next and page Number cells.
        ///     .pageCurrentNumber  : the style of the currently selected page number link.
        ///     .pageGroups         : the style of the page groups cell.
        /// Parameters:
        ///     MaxVisiblePageNumbers   : the number of VISIBLE page links.
        ///     PageCounterText         : the text to display at the beginning of the page counter.
        ///     PageCounterTotalText    : the text to display before the count of pages inside the page counter.
        ///     TheGrid                 : the gridview control.
        ///     
        /// </summary>
        public class FullGridPager
        {
            private const int DEFAULT_MAX_VISIBLE = 0;
            private const string DEFAULT_COUNTER_TEXT = "Σελίδα";
            private const string DEFAULT_TOTAL_TEXT = "από";
     
            protected int maxVisiblePageNumbers;
            protected int firstPageNumber;
            protected int lastPageNumber;
            protected string pageCounterText;
            protected string pageCounterTotalText;
            protected GridView theGrid;
            protected GridViewRow theGridViewRow;
     
            public FullGridPager(GridView TheGrid)
            {
                // Default Constructor		
                maxVisiblePageNumbers = DEFAULT_MAX_VISIBLE;
                pageCounterText = DEFAULT_COUNTER_TEXT;
                pageCounterTotalText = DEFAULT_TOTAL_TEXT;
                theGrid = TheGrid;
            }
     
            public FullGridPager(GridView TheGrid, int MaxVisible, string CounterText, string TotalText)
            {
                // Parameterized constructor
                maxVisiblePageNumbers = MaxVisible;
                pageCounterText = CounterText;
                pageCounterTotalText = TotalText;
                theGrid = TheGrid;
            }
     
            public int MaxVisiblePageNumbers
            {
                get { return maxVisiblePageNumbers; }
                set { maxVisiblePageNumbers = value; }
            }
     
            public string PageCounterText
            {
                get { return pageCounterText; }
                set { pageCounterText = value; }
            }
     
            public string PageCounterTotalText
            {
                get { return pageCounterTotalText; }
                set { pageCounterTotalText = value; }
            }
     
            public GridView TheGrid
            {
                get { return theGrid; }
            }
     
            public void CreateCustomPager(GridViewRow PagerRow)
            {
                // Create custom pager inside the Grid's pagerTemplate.
                // An html table is used to format the custom pager.
     
                // No data to display.
                if (PagerRow == null) return;
     
                theGridViewRow = PagerRow;
     
                HtmlTable pagerInnerTable = (HtmlTable)PagerRow.Cells[0].FindControl("pagerInnerTable");
                if (pagerInnerTable != null)
                {
                    // default dynamic cell position. 
                    // (after the pageCount, the "First" and the "Previous" cells).            
                    int insertCellPosition = 2;
                    if (theGrid.PageIndex == 0)
                    {
                        // The first page is currently displayed.
                        // Hide First and Previous page navigation.
                        pagerInnerTable.Rows[0].Cells[1].Visible = false;
                        pagerInnerTable.Rows[0].Cells[2].Visible = false;
                        // Change the default dynamic cell to 1.
                        insertCellPosition = 0;
                    }
     
                    CalcFirstPageNumber();
                    CalcLastPageNumber();
     
                    CreatePageNumbers(pagerInnerTable, insertCellPosition);
     
                    int lastCellPosition = pagerInnerTable.Rows[0].Cells.Count - 1;
                    if (theGrid.PageIndex == theGrid.PageCount - 1)
                    {
                        // The last page is currently displayed.
                        // Hide Next and Last page navigation.                
                        pagerInnerTable.Rows[0].Cells[lastCellPosition - 1].Visible = false;
                        pagerInnerTable.Rows[0].Cells[lastCellPosition].Visible = false;
                    }
     
                    UpdatePageCounter(pagerInnerTable);
                }
            }
     
            private void CreatePageNumbers(HtmlTable pagerInnerTable, int insertCellPosition)
            {
                for (int i = firstPageNumber, pos = 1; i <= lastPageNumber; i++, pos++)
                {
                    // Create a new table cell for every data page number.
                    HtmlTableCell tableCell = new HtmlTableCell();
                    if (theGrid.PageIndex == i - 1)
                        tableCell.Attributes.Add("class", "pageCurrentNumber");
                    else
                        tableCell.Attributes.Add("class", "pagePrevNextNumber");
     
                    // Create a new LinkButton for every data page number.
                    LinkButton lnkPage = new LinkButton();
                    lnkPage.ID = "Page" + i.ToString();
                    lnkPage.Text = i.ToString();
                    lnkPage.CommandName = "Page";
                    lnkPage.CommandArgument = i.ToString();
                    lnkPage.CssClass = "pagerLink";
     
                    // Place link inside the table cell; Add the cell to the table row.                
                    tableCell.Controls.Add(lnkPage);
                    pagerInnerTable.Rows[0].Cells.Insert(insertCellPosition + pos, tableCell);
                }
            }
     
            private void CalcFirstPageNumber()
            {
                // Calculate the first, visible page number of the pager.             
                firstPageNumber = 1;
                if (MaxVisiblePageNumbers == DEFAULT_MAX_VISIBLE)
                    MaxVisiblePageNumbers = theGrid.PageCount;
     
                if (theGrid.PageCount > MaxVisiblePageNumbers)
                {
                    // Seperate page numbers in groups if necessary.
                    if ((theGrid.PageIndex + 1) > maxVisiblePageNumbers)
                    {
                        // Calculate the group to display.
                        // Example: 
                        //      GridView1.PageCount = 12
                        //      maxVisiblePageNumbers = 4
                        //      GridView1.PageIndex+1 = 7
                        //      --> pageGroup = 2       (Page numbers: 5, 6, 7, 8)
                        decimal pageGroup = Math.Ceiling((decimal)(theGrid.PageIndex + 1) / MaxVisiblePageNumbers);
                        // Calculate the first page number for the group to display.
                        // Example :
                        //      if pageGroup = 1 (Page numbers: 1,2,3,4) --> firstPageNumber = 1
                        //      if pageGroup = 2 (Page numbers: 5,6,7,8) --> firstPageNumber = 5
                        //      if pageGroup = 3 (Page numbers: 9,10,11,12) --> firstPageNumber = 9                        
                        firstPageNumber = (int)(1 + (MaxVisiblePageNumbers * (pageGroup - 1)));
                    }
                }
            }
     
            private void CalcLastPageNumber()
            {
                // Calculate the last, visible page number of the pager.
                lastPageNumber = theGrid.PageCount;
                if (MaxVisiblePageNumbers == DEFAULT_MAX_VISIBLE)
                    MaxVisiblePageNumbers = theGrid.PageCount;
     
                if (theGrid.PageCount > MaxVisiblePageNumbers)
                {
                    lastPageNumber = firstPageNumber + (MaxVisiblePageNumbers - 1);
                    if (theGrid.PageCount < lastPageNumber)
                        lastPageNumber = theGrid.PageCount;
                }
            }
     
            private void UpdatePageCounter(HtmlTable pagerInnerTable)
            {
                // Display current page number and total number of pages.        
                Label pageCounter = (Label)pagerInnerTable.Rows[0].Cells[0].FindControl("lblPageCounter");
                pageCounter.Text = "&nbsp;" + PageCounterText + "&nbsp;" + (theGrid.PageIndex + 1).ToString() + "&nbsp;" + PageCounterTotalText + "&nbsp;" + theGrid.PageCount.ToString() + "&nbsp";
            }
        }
    }

    Voici le code. Un exemple de ce que j'aimerai est :
    First < 1 2 3 4 5 6 7 8 9 10 ... 1500 > Last >>

    J'espere que je suis assez clair ! Merci sincere a tous !

  5. #5
    Expert confirmé
    Avatar de Immobilis
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2004
    Messages
    6 559
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 559
    Par défaut
    Salut,

    Je dirai qu'il faut que tu interviennes dans cette fonction pour limiter le nombre de tours de la boucle:
    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
     
            private void CreatePageNumbers(HtmlTable pagerInnerTable, int insertCellPosition)
            {
                for (int i = firstPageNumber, pos = 1; i <= lastPageNumber; i++, pos++)
                {
                    // Create a new table cell for every data page number.
                    HtmlTableCell tableCell = new HtmlTableCell();
                    if (theGrid.PageIndex == i - 1)
                        tableCell.Attributes.Add("class", "pageCurrentNumber");
                    else
                        tableCell.Attributes.Add("class", "pagePrevNextNumber");
     
                    // Create a new LinkButton for every data page number.
                    LinkButton lnkPage = new LinkButton();
                    lnkPage.ID = "Page" + i.ToString();
                    lnkPage.Text = i.ToString();
                    lnkPage.CommandName = "Page";
                    lnkPage.CommandArgument = i.ToString();
                    lnkPage.CssClass = "pagerLink";
     
                    // Place link inside the table cell; Add the cell to the table row.                
                    tableCell.Controls.Add(lnkPage);
                    pagerInnerTable.Rows[0].Cells.Insert(insertCellPosition + pos, tableCell);
                }
            }
    Pour voir si j'ai raison, est-ce que tu peux faire un test en remplaçant "lastPageNumber" par 10 pour voir.

    A+
    "Winter is coming" (ma nouvelle page d'accueil)

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    145
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 145
    Par défaut
    Oui en effet cela controle le nombre de numeros de page qui apparaissent.
    Dans notre cas, Page 1 of 35 << First < 1 2 3 4 5 6 7 8 9 10 > Last >>

    Maintenant ce que je n'arrive pas a saisir c'est comment gerer les 3 petits points.

  7. #7
    Expert confirmé
    Avatar de Immobilis
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2004
    Messages
    6 559
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 559
    Par défaut
    Imagine un curseur de plus ou moins 3 pages qui s'affiche avant et après la page courante.
    << First < 1 2 3 4... > Last >>
    << First < 1 2 3 4 5 6 7 ... > Last >>
    << First < ... 11 12 13 14 15 16 17 ... > Last >>
    Dans ta boucle for tu ajoutes un test pour afficher uniquement les numéros inférieurs à PageCourante +- 3. Ou bien tu la fais démarrer à PageCourante -3 et terminer à PageCourante +3
    Tu peux aussi ajouter des liens qui permettent de faire des sauts de pages de +-10 pages.

    A+
    "Winter is coming" (ma nouvelle page d'accueil)

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    145
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 145
    Par défaut
    Alors j'ai fait :
    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
     private void CreatePageNumbers(HtmlTable pagerInnerTable, int insertCellPosition)
            {
                for (int i = firstPageNumber, pos = 1; i <= lastPageNumber; i++, pos++)
                {
                    // Create a new table cell for every data page number.
                    HtmlTableCell tableCell = new HtmlTableCell();
                    int currentpage = theGrid.PageIndex;
                    if (theGrid.PageIndex == i - 1)
                        tableCell.Attributes.Add("class", "pageCurrentNumber");
     
                    else
                        tableCell.Attributes.Add("class", "pagePrevNextNumber");
                    if (i < currentpage + 4 && i > currentpage - 4)
                    {
                        // Create a new LinkButton for every data page number.
                        LinkButton lnkPage = new LinkButton();
                        lnkPage.ID = "Page" + i.ToString();
                        lnkPage.Text = i.ToString();
                        lnkPage.CommandName = "Page";
                        lnkPage.CommandArgument = i.ToString();
                        lnkPage.CssClass = "pagerLink";
     
     
                        // link Place inside the table cell; Add the cell to the table row.                
                        tableCell.Controls.Add(lnkPage);
                        pagerInnerTable.Rows[0].Cells.Insert(insertCellPosition + pos, tableCell);
                    }
     
                }
            }
    Mais ca ne marche pas super bien.

    Apres 6, je me retrouve avec :
    << First < > 2 3 4 5 6 7 8 Last >>

    Apres 7 :
    << First < > Last >> 3 4 5 6 7 8 9

    A 8, ca ne marche plus:
    Specified argument was out of the range of valid values.
    Parameter name: index
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
    Parameter name: index

    Source Error:


    Line 154: // link Place inside the table cell; Add the cell to the table row.
    Line 155: tableCell.Controls.Add(lnkPage);
    Line 156: pagerInnerTable.Rows[0].Cells.Insert(insertCellPosition + pos, tableCell);
    Line 157: }
    Line 158:
    help please......

    edit: il semblerait que je ne l'ai pas mis au bon endroit ce test... en tout cas ca doit venir d'ici...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    pagerInnerTable.Rows[0].Cells.Insert(insertCellPosition + pos, tableCell);
    edit 2 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    pagerInnerTable.Rows[0].Cells.Insert(insertCellPosition + pos - currentpage + 4, tableCell);
    Il reste plus finalement qu'a tester si on est a la page page 4, on fait
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    pagerInnerTable.Rows[0].Cells.Insert(insertCellPosition + pos, tableCell);

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

Discussions similaires

  1. trois petits points
    Par LeCogiteur dans le forum Langage
    Réponses: 2
    Dernier message: 31/03/2008, 10h55
  2. [XSLT] Un texte et 3 petits points...
    Par Dadv dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 04/10/2005, 15h01

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