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 :

Pb : impossible de trier sur le datagrid


Sujet :

ASP.NET

  1. #1
    Membre éclairé
    Inscrit en
    Janvier 2005
    Messages
    460
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Janvier 2005
    Messages : 460
    Par défaut Pb : impossible de trier sur le datagrid
    Bonjour,

    j'ai un datagrid que j'affiche mais je change son datasource en cours de route : resultat, sur la nouvelle version du datagrid, Exception des que je veux trier.

    Exception :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    [HttpException (0x80004005): The GridView 'GridView1' fired event Sorting which wasn't handled.]
    Code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     GridView1.DataSource = "";
                GridView1.DataSourceID = "";
                GridView1.DataSource=ObjectDataSource3   ;
                GridView1.AllowPaging = true;
                GridView1.AllowSorting = true;
                GridView1.DataBind();
    Merci pour votre aide precieuse

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    16
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2005
    Messages : 16
    Par défaut
    hello,

    si tu met un "order by" dans ta requète tu ne sais pas trier ?

    ...

  3. #3
    Membre extrêmement actif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 240
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 240
    Par défaut
    tu n'as pas implémenté l'évenement pour trier ton datagrid.
    en fait il pourrait le faire tout seul si tu mettais une datasource via le designer.

  4. #4
    Membre éclairé
    Inscrit en
    Janvier 2005
    Messages
    460
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Janvier 2005
    Messages : 460
    Par défaut
    Salut rattlehead,

    comment puis-je faire pour l'implémenter ??




  5. #5
    Expert confirmé Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Par défaut
    Bonjour,

    Essayer :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DataGridView.DataGridViewColumnSortMode=DataGridViewColumnSortMode.Automatic;

  6. #6
    Membre éclairé
    Inscrit en
    Janvier 2005
    Messages
    460
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Janvier 2005
    Messages : 460
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Error	1	'System.Web.UI.WebControls.GridView' does not contain a definition for 'DataGridViewColumnSortMode'	C:\Documents and Settings\benjamin\Desktop\job-logging\tailormade\ManageAccounts.aspx.cs	100	19	C:\...\job-logging\
    Error	2	The name 'DataGridViewColumnSortMode' does not exist in the current context	C:\Documents and Settings\benjamin\Desktop\job-logging\tailormade\ManageAccounts.aspx.cs	100	48	C:\...\job-logging\
    Apparemment impossible de le faire

  7. #7
    Membre extrêmement actif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 240
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 240
    Par défaut
    tu as un évenement OnSorting un truc dans le genre dans le Gridview. il faut juste l'implémenter. regarde dans la msdn ou sur le net.
    sinon pour pouvoir le faire sans coder il faut que ton gridview est une datasourceID que dataSource que tu peux créer via l'assistant.

  8. #8
    Membre éclairé
    Inscrit en
    Janvier 2005
    Messages
    460
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Janvier 2005
    Messages : 460
    Par défaut
    Jai vu Onsorting sur msdn mais je ne peux l'implementer, cela n'existe pas.

  9. #9
    Membre extrêmement actif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 240
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 240
    Par défaut
    pas possible. mate sur Visual studio les évenements disponibles pour une gridview.

  10. #10
    Membre extrêmement actif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 240
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 240
    Par défaut
    c'est tout bonnement sorting!

  11. #11
    Membre éclairé
    Inscrit en
    Janvier 2005
    Messages
    460
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Janvier 2005
    Messages : 460
    Par défaut
    Ok rattlehead mais je mets quoi dans la procedure ?
    Ca m'a permis de ne plus avoir d'exception mais ca ne trie pas.

  12. #12
    Membre extrêmement actif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 240
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 240
    Par défaut
    mate dans la msdn. il y a surement un exemple.

  13. #13
    Membre éclairé
    Inscrit en
    Janvier 2005
    Messages
    460
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Janvier 2005
    Messages : 460
    Par défaut
    Il n'y a qu'un exemple pas clair et en VB, si tu en as un mieux ca m'interesse !

  14. #14
    Membre extrêmement actif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 240
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 240
    Par défaut
    c'est du vice. j'ai pris l'aide de visual studio j'ai tapé gridview ensuite je suis allé sur event j'ai cliqué sur sorting et oh miracle :
    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
     
    The following code example demonstrates how to use the Sorting event to cancel a sorting operation.
     
    Visual Basic  Copy Code 
    <%@ Page language="VB" %>
     
    <script runat="server">
     
      Sub CustomersGridView_Sorting(sender As Object, e As GridViewSortEventArgs)
     
        ' Cancel the sorting operation if the user attempts
        ' to sort by address.
        If e.SortExpression = "Address" Then
     
          e.Cancel = True
          Message.Text = "You cannot sort by address."
          SortInformationLabel.Text = ""
     
        Else
     
          Message.Text = ""
     
        End If
     
      End Sub
     
      Sub CustomersGridView_Sorted(ByVal sender As Object, ByVal e As EventArgs)
     
        ' Display the sort expression and sort direction.
        SortInformationLabel.Text = "Sorting by " & _
          CustomersGridView.SortExpression.ToString() & _
          " in " & CustomersGridView.SortDirection.ToString() & _
          " order."
     
      End Sub
     
    </script>
     
    <html>
      <body>
        <form runat="server">
     
          <h3>GridView Sorted and Sorting Example</h3>
     
          <asp:label id="Message"
            forecolor="Red"
            runat="server"/>
     
          <br/>
     
          <asp:label id="SortInformationLabel"
            forecolor="Navy"
            runat="server"/>
     
          <br/>  
     
          <asp:gridview id="CustomersGridView" 
            datasourceid="CustomersSource" 
            autogeneratecolumns="true"
            allowpaging="true"
            emptydatatext="No data available." 
            allowsorting="true"
            onsorting="CustomersGridView_Sorting"
            onsorted="CustomersGridView_Sorted"  
            runat="server">
     
          </asp:gridview>
     
          <!-- This example uses Microsoft SQL Server and connects  -->
          <!-- to the Northwind sample database. Use an ASP.NET     -->
          <!-- expression to retrieve the connection string value   -->
          <!-- from the Web.config file.                            -->
          <asp:sqldatasource id="CustomersSource"
            selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
            connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
            runat="server"/>
     
        </form>
      </body>
    </html>
     
     
     
    C#  Copy Code 
    <%@ Page language="C#" %>
     
    <script runat="server">
     
      void CustomersGridView_Sorting(Object sender, GridViewSortEventArgs e)
      {
        // Cancel the sorting operation if the user attempts
        // to sort by address.
        if (e.SortExpression == "Address")
        {
          e.Cancel = true;
          Message.Text = "You cannot sort by address.";
          SortInformationLabel.Text = "";
        }
        else
        {
          Message.Text = "";
        }
      }
     
      void CustomersGridView_Sorted(Object sender, EventArgs e)
      {
        // Display the sort expression and sort direction.
        SortInformationLabel.Text = "Sorting by " +
          CustomersGridView.SortExpression.ToString() +
          " in " + CustomersGridView.SortDirection.ToString() +
          " order.";
      }
     
    </script>
     
    <html>
      <body>
        <form runat="server">
     
          <h3>GridView Sorting Example</h3>
     
          <asp:label id="Message"
            forecolor="Red"
            runat="server"/>
     
          <br/>
     
          <asp:label id="SortInformationLabel"
            forecolor="Navy"
            runat="server"/>
     
          <br/>  
     
          <asp:gridview id="CustomersGridView" 
            datasourceid="CustomersSource" 
            autogeneratecolumns="true"
            allowpaging="true"
            emptydatatext="No data available." 
            allowsorting="true"
            onsorting="CustomersGridView_Sorting"
            onsorted="CustomersGridView_Sorted"  
            runat="server">
     
          </asp:gridview>
     
          <!-- This example uses Microsoft SQL Server and connects  -->
          <!-- to the Northwind sample database. Use an ASP.NET     -->
          <!-- expression to retrieve the connection string value   -->
          <!-- from the Web.config file.                            -->
          <asp:sqldatasource id="CustomersSource"
            selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
            connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
            runat="server"/>
     
        </form>
      </body>
    </html>

  15. #15
    Membre éclairé
    Inscrit en
    Janvier 2005
    Messages
    460
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Janvier 2005
    Messages : 460
    Par défaut
    J'avais vu Rattlehead mais ce que tu me montres ne me permet pas de trier.

  16. #16
    Membre extrêmement actif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 240
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 240
    Par défaut
    bah il te suffit de modifier un peu se code. c'est en fonction de e.SortExpression. donc il faut jouer la dessus.

  17. #17
    Membre éclairé
    Inscrit en
    Janvier 2005
    Messages
    460
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Janvier 2005
    Messages : 460
    Par défaut
    Jen'ai tjrs pas trouver la solution.

  18. #18
    Membre éclairé
    Inscrit en
    Janvier 2005
    Messages
    460
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Janvier 2005
    Messages : 460
    Par défaut
    up !

Discussions similaires

  1. [PEAR][DB][Datagrid] Impossible de trier
    Par bilou972 dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 25/05/2008, 17h47
  2. Connexion depuis LAN impossible vers Mysql sur RH8
    Par RamDevTeam dans le forum Administration
    Réponses: 4
    Dernier message: 10/02/2005, 15h28
  3. Trier sur n critères (ou dimensions, ou colonnes?)
    Par sbeu dans le forum Algorithmes et structures de données
    Réponses: 10
    Dernier message: 10/10/2004, 10h43
  4. [VB.NET] Exécuter une fonction VB sur un Datagrid
    Par MiJack dans le forum Windows Forms
    Réponses: 3
    Dernier message: 24/09/2004, 14h45
  5. Impossible de rebooter sur la partition windows
    Par Ancien_Do.Urden dans le forum Administration système
    Réponses: 8
    Dernier message: 18/03/2004, 22h10

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