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 :

Modélisation avec des gridview


Sujet :

ASP.NET

  1. #1
    Membre éclairé
    Inscrit en
    Février 2006
    Messages
    522
    Détails du profil
    Informations forums :
    Inscription : Février 2006
    Messages : 522
    Par défaut Modélisation avec des gridview
    Bonjour,

    J'aimerais bien modéliser la page HTML suivante

    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
    <table style="width: 100%;" border="0">
            <tr>
                <th>
                </th>
                <th>
                </th>
                <th colspan="12" style="background-color: Silver; color: White; font-weight: bold">
                    Header1
                </th>
            </tr>
            <tr style="background-color: Silver; color: White; font-weight: bold">
                <th rowspan="2">
                   Name
                </th>
                <th rowspan="2">
                   date             </th>
                <th colspan="4">
                    period1
                </th>
                <th colspan="4">
                    period2
                </th>
                <th colspan="4">
                    period3
                </th>
            </tr>
            <tr>
                <th style="background-color: Silver; color: White; font-weight: bold">
                   imagPeriod1
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                   imag2Period1
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                 imag3Period1
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                    Total
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imagPeriod2
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imag2Period2
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imag3Period2
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                    Total
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imagPeriod3
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imag2Period3
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imagPeriod3
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                    Total
                </th>
            </tr>
            <tr style="background-color: #CCECFF;">
                <td>
                    bablala
                </td>
                <td>
                    <img src="../Images/statusOK.png" />
                  07/03/2010            </td>
                <td>
                    1
                </td>
                <td>
                    2
                </td>
                <td>
                    3
                </td>
                <td>
                    6
                </td>
                <td>
                    400
                </td>
                <td>
                    500
                </td>
                <td>
                    600
                </td>
                <td>
                    1500
                </td>
                <td>
                    1
                </td>
                <td>
                   2
                </td>
                <td>
                   3            </td>
                <td>
                    6
                </td>
            </tr>

    Comment modéliser cela avec une gridview si possible pour que les headers correspondent? on doit s'arranger avec "les headertemplate"?

  2. #2
    Membre éclairé
    Inscrit en
    Février 2006
    Messages
    522
    Détails du profil
    Informations forums :
    Inscription : Février 2006
    Messages : 522
    Par défaut
    Bonjour,

    J'ai déclaré une gridview comme suit :

    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
     
    <asp:GridView runat="server" ID="gvName" AutoGenerateColumns="False" CssClass="gvName">
        <RowStyle BackColor="#CCECFF" />
        <AlternatingRowStyle BackColor="#F1F1F1" />
     
        <RowStyle HorizontalAlign="Center" />
        <Columns>
        <asp:TemplateField >
     
        </asp:TemplateField>
     
            <asp:BoundField DataField="Name" HeaderText="<%$ Resources:Resources, Name %>"
                HeaderStyle-Width="15%" />...
     
    </Columns>
    Ce qui est bizarre, c'est que le templatefield me rajoute automatiquement une colonne du coup tout mon tableau est décalé. Une idée de pourquoi?

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

    Informations forums :
    Inscription : Septembre 2007
    Messages : 1 137
    Par défaut
    Tu n'a qu'a mettre le templateField á visible = false

  4. #4
    Membre éclairé
    Inscrit en
    Février 2006
    Messages
    522
    Détails du profil
    Informations forums :
    Inscription : Février 2006
    Messages : 522
    Par défaut
    J'ai oubilé une partie du code :p donc en fait dans le templatefield, j'ai aussi dse headers (donc des <th> notamment). Je peux donc pas le mettre à false :p

  5. #5
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Par défaut
    Citation Envoyé par trihanhcie Voir le message
    Ce qui est bizarre, c'est que le templatefield me rajoute automatiquement une colonne du coup tout mon tableau est décalé. Une idée de pourquoi?
    Ben ça n'a rien de bizarre... un field (TemplateField, BoundField ou autre) correspond à une colonne, donc si tu en rajoutes un, ça rajoute une colonne. Le GridView a fait exactement ce que tu lui as demandé (c'est souvent le problème avec les ordinateurs )

    De toutes façons, ton TemplateField ne sert à rien puisque tu ne mets rien dedans...

    EDIT: j'avais pas vu le dernier message...

    Citation Envoyé par trihanhcie Voir le message
    J'ai oubilé une partie du code :p donc en fait dans le templatefield, j'ai aussi dse headers (donc des <th> notamment). Je peux donc pas le mettre à false :p
    C'est des en-têtes de ligne ou de colonne que tu veux ? si c'est des en-têtes de ligne, c'est normal que ça décale tout, non ? Et si c'est des en-têtes de colonne, c'est pas un TemplateField qu'il faut utiliser... regarde plutôt du côté de la propriété HeaderStyle du GridView

  6. #6
    Membre éclairé
    Inscrit en
    Février 2006
    Messages
    522
    Détails du profil
    Informations forums :
    Inscription : Février 2006
    Messages : 522
    Par défaut
    En fait, comme je disais plus haut, je voudrais l'équivalent du code HTML suivant avec une gridview

    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
     
    <tr>
                <th>
                </th>
                <th>
                </th>
                <th colspan="12" style="background-color: Silver; color: White; font-weight: bold">
                    Periode
                </th>
            </tr>
            <tr style="background-color: Silver; color: White; font-weight: bold">
                <th rowspan="2">
                   Nom            </th>
                <th rowspan="2">
                   date             </th>
                <th colspan="4">
                    period1
                </th>
                <th colspan="4">
                    period2
                </th>
                <th colspan="4">
                    period3
                </th>
            </tr>
    <tr>
                <th style="background-color: Silver; color: White; font-weight: bold">
                   imagPeriod1
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                   imag2Period1
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                 imag3Period1
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                    Total
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imagPeriod2
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imag2Period2
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imag3Period2
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                    Total
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imagPeriod3
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imag2Period3
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                                   imagPeriod3
     
                </th>
                <th style="background-color: Silver; color: White; font-weight: bold">
                    Total
                </th>
            </tr>

    ou quelque chose de mieux si vous voulez ^^
    Il y aurait une ligne avec "juste" un en tete "Periode" en header
    Une en ligne avec des header Nom et DAte puis un groupement de "periode"
    Sur la 3e ligne de header (avec un rowspan=2 pour les 2 premieres lignes) puis 3 colonnes par groupement de période

    et ensuite la gridview

  7. #7
    Membre Expert
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    826
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juin 2006
    Messages : 826
    Par défaut
    Salut,

    petit problème, le gridview ne gère pas les éléments th pour l'entête. Pour lui, HeaderRow est simplement une ligne tr comme les autres...

    Pourquoi as tu besoin des élements th ?

  8. #8
    Membre éclairé
    Inscrit en
    Février 2006
    Messages
    522
    Détails du profil
    Informations forums :
    Inscription : Février 2006
    Messages : 522
    Par défaut
    heu bah c'était comme ca, j'avais fait ce tableau en html pour une maquette, ca m'a paru logique de mettre un th pour les header. peu importe pour moi si ce sont des th ou td :p

    Le gridview te génère th pour tes header il me semble :/

Discussions similaires

  1. Réponses: 4
    Dernier message: 22/10/2012, 10h28
  2. gridview avec des sous regroupements
    Par DeveloppeurWeb dans le forum ASP.NET
    Réponses: 3
    Dernier message: 30/05/2011, 13h31
  3. Réponses: 2
    Dernier message: 14/06/2008, 18h03
  4. Réponses: 3
    Dernier message: 05/01/2007, 10h44
  5. Réponses: 4
    Dernier message: 05/12/2006, 11h43

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