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 :

Tri et pagination du datagrid qui ne marche pas


Sujet :

ASP.NET

  1. #1
    Membre régulier Avatar de paradeofphp
    Inscrit en
    Décembre 2005
    Messages
    313
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 313
    Points : 94
    Points
    94
    Par défaut Tri et pagination du datagrid qui ne marche pas
    Salut,
    J'ai un souci avec tout mes Datagrid. En fait, j'ai le tri par colonne et la pagination qui ne marche pas et pourtant, j'ai mis les 2 propriétés AllowPaging et AllowSorting a True. Voici a quoi ressemble mon DataGrid :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    asp:datagrid id="dgStat" runat="server" Width="100%" CellPadding="4" BackColor="White" BorderColor="#DEDFDE"
    											ForeColor="Black" AllowSorting="True" GridLines="Vertical" BorderWidth="1px" BorderStyle="None" AllowPaging="True">
    											<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#CE5D5A"></SelectedItemStyle>
    											<AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
    											<ItemStyle BackColor="#F7F7DE"></ItemStyle>
    											<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#6B696B"></HeaderStyle>
    											<FooterStyle BackColor="#CCCC99"></FooterStyle>
    											<PagerStyle HorizontalAlign="Right" ForeColor="Black" BackColor="#F7F7DE" Mode="NumericPages"></PagerStyle>
    										</asp:datagrid>

    Je vous informe que je rajoute manuellement les lignes au dataGrid, meme les noms de colonnes sont personnalisées. SI vous voulez voir le code qui remplit le datagrid, je vous le montre. Sinon voici le code de pagination et du tri :

    Pagination :


    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
            Private Sub dgStat_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgStat.PageIndexChanged
     
                Try
                    dgStat.CurrentPageIndex = e.NewPageIndex
                    ' On teste si on doit activer le bouton Export vers CSV
                    Dim myDataTable As DataTable = CType(Me.getVariableSession("myDataTable"), DataTable)
                    tabRow = CType(Me.getVariableSession("tabRow"), Integer())
                    CreatDataGrid(myDataTable)
                    'dgStat.DataBind()
     
                Catch ex As Exception
                    System.Diagnostics.Debug.Write(ex.Message)
                End Try
     
            End Sub
    Tri : cette fonction est encore incomplete :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
            Private Sub dgStat_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgStat.SortCommand
                SortField = e.SortExpression
            End Sub
    Merci

  2. #2
    Membre régulier Avatar de paradeofphp
    Inscrit en
    Décembre 2005
    Messages
    313
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 313
    Points : 94
    Points
    94
    Par défaut
    Salut,
    Personne n'a une idée du problème ?

  3. #3
    Membre confirmé
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2006
    Messages
    400
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 400
    Points : 459
    Points
    459
    Par défaut
    Bonjour

    Pourquoi avoir commenté "dgStat.DataBind()" dans ta pagination ? Il faut forcément repasser par le bind, non?

    Voilà deux bouts de code pour un grid remplit dans le code 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
     
      Sub GridNews_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
            Try
                GridNews.PageIndex = e.NewPageIndex
               'Trie aprés changement de page
                GridNews.Sort("DateMaj", SortDirection.Descending)
            Catch
            End Try
        End Sub
    ...
        Protected Sub GridNews_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridNews.Sorting
            Try
                Dim sSortExpression As String = e.SortExpression
                Dim sSortDirection As String = e.SortDirection
                Dim oDataView As New Data.DataView(oDataset.Tables(0))
                oDataView.Sort = "DateMaj DESC"
                GridNews.DataSource = oDataView
                'Le Bind s'effectue ici
                GridNews.DataBind()
            Catch
            End Try
        End Sub
    En esperant que ça puisse t'aider

    A bientôt

Discussions similaires

  1. [MySQL] MySql tri par ordre qui ne marche pas
    Par Invité dans le forum PHP & Base de données
    Réponses: 12
    Dernier message: 17/06/2010, 17h12
  2. [SWING] KeyListener qui ne marche pas
    Par kindool dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 10/01/2005, 19h04
  3. Iptables configuration qui ne marche pas....
    Par The_Nail dans le forum Sécurité
    Réponses: 7
    Dernier message: 03/02/2004, 14h27
  4. Réponses: 3
    Dernier message: 08/09/2003, 15h06
  5. Réponses: 9
    Dernier message: 07/05/2003, 12h57

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