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: Ajouter des lignes


Sujet :

ASP.NET

  1. #1
    Rédacteur
    Avatar de Franck.H
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2004
    Messages
    6 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2004
    Messages : 6 951
    Points : 12 462
    Points
    12 462
    Par défaut GridView: Ajouter des lignes


    Je voulais savoir s'il y avait un moyen quelconque d'ajouter des lignes à l'endroit choisi dans un GridView ? Il sais qu'il est rempli directement depuis un DataSet mais il faudrait que j'ajoute des lignes à partir du code behind VB.Net !


    Mon Site
    Ma bibliothèque de gestion des chaînes de caractères en C

    L'imagination est plus importante que le savoir. A. Einstein

    Je ne répond à aucune question technique par MP, merci d'avance !

  2. #2
    Rédacteur
    Avatar de Franck.H
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2004
    Messages
    6 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2004
    Messages : 6 951
    Points : 12 462
    Points
    12 462
    Par défaut
    Alors j'ai trouvé comment ajouter des lignes mais j'ai cependant un problème ! J'ai un GridView qui est lié à un DataSource. Dans la méthode RowDataBound, je commence par ajouter mes deux lignes en question en remplacement du header que je cache. A l'affichage sur la page web pas de problème tout marche nickel mais une fois exporté en Excel il n'y a que la seconde ligne (gvr2) qui s'affiche mais pas l'autre, je cherche depuis tout l'aprem mais n'arrive à rien !

    Voici le code:
    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
        Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
            If tmp_i = 0 Then
                Dim tbl As Table = CType(GridView1.Controls(0), Table)
                Dim gvr As New GridViewRow(0, 0, DataControlRowType.EmptyDataRow, DataControlRowState.Normal)
     
                gvr.Cells.Add(New TableCell())
                gvr.Cells.Add(New TableCell())
                gvr.Cells.Add(New TableCell())
     
                tbl.Controls.AddAt(0, gvr)
     
                gvr.Cells(0).ColumnSpan = 7
                gvr.Cells(1).ColumnSpan = 7
                gvr.Cells(2).ColumnSpan = 8
     
                gvr.Cells(0).Text = String.Empty
                gvr.Cells(0).BackColor = Drawing.Color.Transparent
                gvr.Cells(1).Text = "Concentration mg/l"
                gvr.Cells(1).Style.Add("color", "#FFFFFF")
                gvr.Cells(1).Style.Add("background-color", "#1464FC")
                gvr.Cells(1).Style.Add("text-align", "center")
                gvr.Cells(1).Style.Add("border-right-color", "#FFFFFF")
                gvr.Cells(1).Style.Add("border-right-width", "1px")
                gvr.Cells(1).Style.Add("border-right-style", "solid")
                gvr.Cells(2).Text = "Flux g/j"
                gvr.Cells(2).Style.Add("color", "#FFFFFF")
                gvr.Cells(2).Style.Add("background-color", "#1464FC")
                gvr.Cells(2).Style.Add("text-align", "center")
     
                Dim gvr2 As New GridViewRow(1, 1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal)
                For i = 0 To 21
                    gvr2.Cells.Add(New TableCell())
                Next
                tbl.Controls.AddAt(1, gvr2)
                For i = 0 To 21
                    gvr2.Cells(i).Text = "TEST"
                    gvr2.Cells(i).Style.Add("text-align", "center")
                Next
     
                tmp_i = 1
            End If
     
            cur_familly = e.Row.Cells(0).Text
            If cur_familly <> String.Empty Then
                If cur_familly <> "FAMILLE" And cur_familly <> "&nbsp;" Then
                    If cur_familly <> old_familly Then
                        old_familly = cur_familly
     
                        Dim tbl As Table = CType(GridView1.Controls(0), Table)
                        Dim rowId As Integer = tbl.Rows.GetRowIndex(e.Row)
                        Dim gvr As New GridViewRow(rowId, rowId, DataControlRowType.EmptyDataRow, DataControlRowState.Normal)
     
                        gvr.Cells.Add(New TableCell())
                        tbl.Controls.AddAt(rowId, gvr)
     
                        gvr.Cells(0).Text = cur_familly
                        gvr.Cells(0).Style.Add("background-color", "#C0D4FA")
                        gvr.Cells(0).Style.Add("color", "#000000")
                        gvr.Cells(0).Style.Add("font-weight", "bold")
                        gvr.Cells(0).Style.Add("text-align", "center")
                        gvr.Cells(0).ColumnSpan = GridView1.Columns.Count
                    End If
                End If
            End If
     
            For i As Integer = 7 To 10
                Dim l_val As String = e.Row.Cells(i).Text
     
                If l_val.StartsWith(" ") Then
                    e.Row.Cells(i).Text = String.Format("<span style=""color:red;"">{0}</span>", l_val)
                End If
            Next
     
            For i = 2 To 21
                e.Row.Cells(i).Style.Add("text-align", "center")
            Next
        End Sub
    Mon Site
    Ma bibliothèque de gestion des chaînes de caractères en C

    L'imagination est plus importante que le savoir. A. Einstein

    Je ne répond à aucune question technique par MP, merci d'avance !

Discussions similaires

  1. Ajouter des lignes dans GridView
    Par DeveloppeurWeb dans le forum VB.NET
    Réponses: 0
    Dernier message: 01/07/2011, 13h55
  2. Réponses: 2
    Dernier message: 07/08/2006, 16h43
  3. [Fichier] Ajouter des lignes...
    Par Life Hunter dans le forum Langage
    Réponses: 4
    Dernier message: 26/11/2005, 18h28
  4. Réponses: 14
    Dernier message: 22/09/2005, 16h49
  5. [Fichier] Ajout des lignes de doc dans arraylist
    Par 3adoula dans le forum Entrée/Sortie
    Réponses: 9
    Dernier message: 29/04/2004, 22h41

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