begin process at 2010 02 10 12:37:25
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

ASP.Net

 > FIGER UN ENTÊTE DE GRIDVIEW AVEC DÉBORDEMENT HORIZONTAL

FIGER UN ENTÊTE DE GRIDVIEW AVEC DÉBORDEMENT HORIZONTAL


 Description

Il existe plusieurs solutions à base de div (qui figent la première ligne du gridview) mais elle a une contrainte de taille : si le gridview dépasse la taille de la div, l'entête déborde systèmatiquement et la barre horizontale n'entraine que le corps du gridview (illisible, donc).
L'idée, c'est de traiter l'entête dans une table séparée, suivie du gridview, le tout encapsulé dans une div (qui gèrera la barre horizontale).
Dans mon cas, j'ai encapsulé tout celà dans un panel (d'affichage).
J'appelle cette sub dans l'évenement prérender des gridview.
Seul bémol, je n'optiens pas systèmatiquement un alignement des colonnes (si quelqu'un à une idée, d'ailleurs, je suis preneur ...).
Bon code à tous!


Source

  • Protected Sub FreezeGridviewHeader(ByRef GV As GridView, ByRef TableGV As Table, ByRef PanelGV As Panel)
  • ' ATTENTION : penser à placer le EnableViewState (directement dans la page html) à False du gridview sur lequel vous
  • 'appliquez cette sub pour éviter undécalage entre le sélect et la ligne sélectionnée
  • TableGV.Rows.Add(GV.HeaderRow)
  • TableGV.Rows(0).ControlStyle.CopyFrom(GV.HeaderStyle)
  • TableGV.CellSpacing = 3
  • TableGV.CellPadding = 5
  • TableGV.Rows(0).Cells(0).Text = "Items : " & NbrItemsAttenteLB.Text
  • TableGV.Rows(0).Cells(0).Width = Unit.Pixel(70)
  • TableGV.Rows(0).Cells(0).BorderStyle = BorderStyle.Inset
  • TableGV.Rows(0).Cells(0).BorderWidth = Unit.Pixel(1)
  • Dim count As Integer = 1
  • Dim tailleTableau As Integer = 0
  • Dim NbrCellVisibles As Integer = 0
  • For count = 1 To GV.HeaderRow.Cells.Count - 1
  • If GV.Columns(count).Visible = "False" Then
  • TableGV.Rows(0).Cells(count).Visible = "False"
  • Else
  • NbrCellVisibles = NbrCellVisibles + 1
  • TableGV.Rows(0).Cells(count).Width = GV.Columns(count).ItemStyle.Width
  • TableGV.Rows(0).Cells(count).BorderStyle = BorderStyle.Inset
  • TableGV.Rows(0).Cells(count).BorderWidth = Unit.Pixel(1)
  • tailleTableau = tailleTableau + Convert.ToInt32(TableGV.Rows(0).Cells(count).Width.Value) + Convert.ToInt32(TableGV.Rows(0).Cells(count).BorderWidth.Value)
  • End If
  • Next
  • TableGV.Width = Unit.Pixel(tailleTableau + (TableGV.CellPadding + TableGV.CellSpacing) * NbrCellVisibles * 2)
  • End Sub
Protected Sub FreezeGridviewHeader(ByRef GV As GridView, ByRef TableGV As Table, ByRef PanelGV As Panel)

        ' ATTENTION : penser à placer le EnableViewState (directement dans la page html) à False du gridview sur lequel vous 
        'appliquez cette sub pour éviter undécalage entre le sélect et la ligne sélectionnée

        TableGV.Rows.Add(GV.HeaderRow)
        
        TableGV.Rows(0).ControlStyle.CopyFrom(GV.HeaderStyle)

        TableGV.CellSpacing = 3
        TableGV.CellPadding = 5

        TableGV.Rows(0).Cells(0).Text = "Items : " & NbrItemsAttenteLB.Text
        TableGV.Rows(0).Cells(0).Width = Unit.Pixel(70)
        TableGV.Rows(0).Cells(0).BorderStyle = BorderStyle.Inset
        TableGV.Rows(0).Cells(0).BorderWidth = Unit.Pixel(1)


        Dim count As Integer = 1

        Dim tailleTableau As Integer = 0
        Dim NbrCellVisibles As Integer = 0
        For count = 1 To GV.HeaderRow.Cells.Count - 1
            If GV.Columns(count).Visible = "False" Then
                TableGV.Rows(0).Cells(count).Visible = "False"
            Else
                NbrCellVisibles = NbrCellVisibles + 1
                TableGV.Rows(0).Cells(count).Width = GV.Columns(count).ItemStyle.Width
                TableGV.Rows(0).Cells(count).BorderStyle = BorderStyle.Inset
                TableGV.Rows(0).Cells(count).BorderWidth = Unit.Pixel(1)
                tailleTableau = tailleTableau + Convert.ToInt32(TableGV.Rows(0).Cells(count).Width.Value) + Convert.ToInt32(TableGV.Rows(0).Cells(count).BorderWidth.Value)

            End If
        Next
        TableGV.Width = Unit.Pixel(tailleTableau + (TableGV.CellPadding + TableGV.CellSpacing) * NbrCellVisibles * 2)

    End Sub



 Sources de la même categorie

Source avec Zip Source .NET (Dotnet) CUSTOM DATEPIKER DÉRIVANT DE COMPOSITECONTROL par fredzool
Source avec Zip UN MODULE POUR APPRENDRE SQL par Elmarzougui
Source avec Zip Source .NET (Dotnet) BOUTON QUI EMPECHE LE MULTI CLIC AVANT LA FIN DU TRAITEMENT.... par fredzool
Source avec Zip Source .NET (Dotnet) BOUTON AVEC CSS ET USERCONTROL WITH EVENT par fredzool
Source avec Zip Source .NET (Dotnet) CAPTCHA ASP.NET ET JAVASCRIPT par vaan3713

Commentaires et avis

Commentaire de spyz91 le 22/10/2009 16:10:22

Pour aligner les colonnes, peut tre récupérer le paramètre "width" de la colonnes pour l'appliquer au même paramètre dans l'en-tête figé.

header1.width = colonne1.width ?

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,655 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales