Bonjour,
je charge un gridview dans un update panel (ajax), tout se passe bien sauf l'utilisation du "pager" ; quand je clique sur un numéro de page, rien ne se passe... quelqu'un aurait il une idée s'il vous plait ?
Merci d'avance
Bonjour,
je charge un gridview dans un update panel (ajax), tout se passe bien sauf l'utilisation du "pager" ; quand je clique sur un numéro de page, rien ne se passe... quelqu'un aurait il une idée s'il vous plait ?
Merci d'avance
Vérifie les Triggers de l'UP sur le bon évènement du PAger.
Réponse rapide, jsute avant de aprtir en Week-end, donc.......
fais voir ton code de déclaration de ton updPanel ( aspx ) stp.
Salut, 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 <asp:UpdatePanel ID="UpdatePanel_boutons" runat="server"> <ContentTemplate> <asp:Panel ID="Panel1" runat="server" Height="24px" Width="960px"> <br /> <asp:Panel ID="Panel_boutons" runat="server" BorderStyle="Solid" BorderWidth="2px" Height="50px" Width="944px"> <br /> <br /> <asp:Button ID="Button_all_demandes" runat="server" OnClick="Button_all_demandes_Click" Text="Toutes Mes demandes" Font-Bold="False" Width="152px" BackColor="InactiveCaptionText" BorderStyle="Solid" BorderWidth="1px" /> <asp:Button ID="Button_demandes_en_attente" runat="server" OnClick="Button_demandes_en_attente_Click" Text="Mes Demandes en attentes" Font-Bold="True" Width="184px" BackColor="InactiveCaptionText" BorderStyle="Solid" BorderWidth="1px" /> <asp:Button ID="Button_all_ddes" runat="server" OnClick="Button_all_ddes_Click" Text="Toutes Demandes" Width="136px" BackColor="InactiveCaptionText" BorderStyle="Solid" BorderWidth="1px" /> <asp:Button ID="Button_nouvelle_demande" runat="server" OnClick="Button_nouvelle_demande_Click" Text="Nouvelle Demande" Font-Bold="True" Width="136px" BackColor="InactiveCaptionText" BorderStyle="Solid" BorderWidth="1px" /> <asp:Button ID="Button_stats" runat="server" OnClick="Button_stats_Click" Text="Statistiques" BackColor="InactiveCaptionText" BorderStyle="Solid" BorderWidth="1px" /> <asp:Button ID="Button_acceuil" runat="server" Text="Accueil" BackColor="LightCyan" BorderStyle="Solid" BorderWidth="1px" /><br /> <asp:Label ID="Label4" runat="server" Font-Names="GE Inspira" Text="Classé par" Font-Italic="True"></asp:Label> <asp:DropDownList ID="DropDownList_tri" runat="server" Width="136px"> <asp:ListItem Value=" date_demande">Date</asp:ListItem> <asp:ListItem>Montant</asp:ListItem> <asp:ListItem Value="convert(nvarchar,Nature)">Nature</asp:ListItem> </asp:DropDownList> <asp:CheckBox ID="CheckBox_tri" runat="server" Font-Names="GE Inspira" Font-Size="10pt" Text="Décroissant" /><br /> </asp:Panel> <br /> </asp:Panel> </ContentTemplate> </asp:UpdatePanel>
Juste ne lisant ton code il manque deux truc par rapport à ton énoncé :
- les triggers
- le grid view
Si tu les rajoutes, peut être que ça ira.
désolé !! je me suis trompé dUP ; 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 <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="True" CellPadding="4" Font-Names="GE Inspira" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="ID" OnPageIndexChanged="GridView1_PageIndexChanged" OnPageIndexChanging="GridView1_PageIndexChanging" AllowPaging="True" AutoGenerateColumns="False" PageSize="5"> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <SelectedRowStyle BackColor="#C5BBAF" ForeColor="#333333" BorderColor="Red" BorderStyle="Double" BorderWidth="2px" Font-Bold="True" /> <PagerStyle BackColor="InactiveCaption" ForeColor="White" HorizontalAlign="Center" Font-Bold="True" Font-Size="Small" /> <HeaderStyle BackColor="InactiveCaption" Font-Bold="True" ForeColor="Black" /> <AlternatingRowStyle BackColor="White" /> <RowStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" BackColor="InactiveCaptionText" /> <EditRowStyle BackColor="#7C6F57" /> <PagerSettings PageButtonCount="5" Position="Top" /> </asp:GridView> <asp:Label ID="Label_ligne" runat="server" Text="Label" Visible="False"></asp:Label> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="PageIndexChanged" /> <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="PageIndexChanging" /> </Triggers> </asp:UpdatePanel>
Les triggers sont pas obligatoires, il prend par défaut les enfants de l'updatepanel comme triggers
Tu as peu etre une exception au moment de ta requete ajax, si tu as firebug tu peux le voir dans ta reponse, ou sinon en lancant ton projet en debug (f5) tu le saura
Et côté CodeBehind, tu as quoi ?
Perso, sur le PageIndexChanged je fais un DataBind()
Egalement, je ne vois pas source de donnée : SqlDataSoucre ou DataTable ?
J'utilise une sqldatasource. Merci pour les infos, je vais essayer d'executer un databind. Is cela ne fonctionne pas je ferais un debugage pas à pas.
Merci encore !
je viens d'ajouter un databind, et maintenant le gridview disparait au moment où je clique sur la page 2...
Lorsque tu dis que le GridView disparait, tu veux dire qu'il te reste jsute la colonne "Selectionner" ?
Si c'est ça, montre nous comment tu fabrique tes colonne
Si c'est pas ça, il manque du code dans ce que tu nous a envoyer, car ce que tu expose n'est pas possible en l'état du code que l'on a dans le topic.
Voici comment sont chargées les données :
Sinon, pouvez vous me donner un exemple du code que vous mettez dans les gridview.pageindexchanged ?
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 '------------------------------------------------------------ 'CONNEXION SQL SERVER POUR RECEPTION ET SAUVEGARDE DES DONNEES Dim ds_sql As DataSet = New DataSet Dim da_sql As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter Dim maconnexion_sql As SqlClient.SqlConnection = New SqlClient.SqlConnection Dim connexion_string_sql As String Dim commande_sql As SqlClient.SqlCommand = New SqlClient.SqlCommand connexion_string_sql = "data source=FSEPAFRDTBS\SQLEXPRESS;Initial Catalog=Table_VHC_INVT;integrated security=true" maconnexion_sql.ConnectionString = connexion_string_sql maconnexion_sql.Open() 'activation du tri en décroissant Dim tri As String If CheckBox_tri.Checked Then tri = (" DESC") Else tri = ("") End If 'CHARGE LES NUMEROS DE DEMANDES commande_sql.Connection = maconnexion_sql commande_sql.CommandText = "select id,date_demande,statut from demandes ORDER BY " & DropDownList_tri.SelectedValue & tri 'création d'un adapter pour lui enregistrer toutes les nouvelles lignes d'un coup da_sql.SelectCommand = commande_sql da_sql.Fill(ds_sql, "SQL_TABLE_TEMP") GridView1.AutoGenerateColumns = True GridView1.Visible = True GridView1.DataSource = ds_sql.Tables("SQL_TABLE_TEMP") GridView1.DataBind() maconnexion_sql.Close() Panel_details.Visible = True
Si je fais le changement à la main dans le gridview.pageindexchanged, cela fonctionne, par exemple dans mon gridview.pageindexchanged :
1) je charge mes données ;
2 ) GridView1.PageIndex = 2
Cela fonctionne, mais je souhaite utiliser les numéros de pages pour choisir la page à afficher, et là je n'y parviens pas...
Dans le PageIndexChanged, je ne mets que ça : GridView1.DataBind()
Autre point qui me perturbe. Tu mets le AutoGenerateColumns à False côté HTML, puis dans le CodeBehind tu le mets à True. Faut rester cohérent dans la vie, c'est mieu, non ?
Donc fais ton choix, mais si tu mets False, ben faut gérer les colonnes à la main.
Autre point encore, ce que tu présente là, n'est pas un SqlDataSource, c'est une DataTable.
encore autre point. Dans ta définition côté HTML tu utilise un DAtaKey : mais, sauf si je dis une bétise, cele ne fonction qu'avec les SqlDataSource.
Pour tenter de conclure. Commence par faire ton GridView tout seul, sur une page simple pour qu'il marche bien et ensuite, palce le dans un UupdatePanel.
Kenavo
Ok merci beaucoup pour cette aide, je vais faire d'autres tests sans update panel et avancer comme ça.
Merci.
Zoofy les datakeys marchent aussi avec les datatables ( ou autres )
Sinon l'idée de la page de test semble bonne, comme toujours:
On fait un module qui marche dans une page de test puis on l'integre au site.
J'ai retiré tous les updates panel et regénérer le projet et rien ne se passe lorsque je clique sur la page 2 ; voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="True" CellPadding="4" Font-Names="GE Inspira" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="ID" OnPageIndexChanged="GridView1_PageIndexChanged" OnPageIndexChanging="GridView1_PageIndexChanging" AllowPaging="True" PageSize="5" BorderStyle="Solid" BorderWidth="1px" AllowSorting="True"> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <SelectedRowStyle BackColor="#C5BBAF" ForeColor="#333333" BorderColor="Red" BorderStyle="Double" BorderWidth="2px" Font-Bold="True" /> <PagerStyle BackColor="InactiveCaption" ForeColor="White" HorizontalAlign="Center" Font-Bold="True" Font-Size="Small" /> <HeaderStyle BackColor="InactiveCaption" Font-Bold="True" ForeColor="Black" /> <AlternatingRowStyle BackColor="White" /> <RowStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" BackColor="InactiveCaptionText" /> <EditRowStyle BackColor="#7C6F57" /> <PagerSettings PageButtonCount="5" Position="Top" /> </asp:GridView>
Reposte ton CodeBehind, qu'on voit comment tu charge le bouzin.
Poste également le reste du code HTML, il y a peut être un truc qui coince.
voici le code HTML :
et le codebehind :
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 <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="RegulCompta_gestion.aspx.vb" Inherits="NucleusWeb.RegulCompta_new" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Reguls Comptables - Nouvelles Demande</title> <link href="mvwres:34-WebGrid.Resources.WebGrid_Calendar.css,WebGrid, Version=2.2.2.0, Culture=neutral, PublicKeyToken=683aa60800d9b3ae" rel="stylesheet" type="text/css" /> <link href="mvwres:34-WebGrid.Resources.WebGrid_Calendar.css,WebGrid, Version=2.2.2.0, Culture=neutral, PublicKeyToken=683aa60800d9b3ae" rel="stylesheet" type="text/css" /> <link href="mvwres:34-WebGrid.Resources.WebGrid_Calendar.css,WebGrid, Version=2.2.2.0, Culture=neutral, PublicKeyToken=683aa60800d9b3ae" rel="stylesheet" type="text/css" /> <link href="mvwres:35-WebGrid.Resources.WebGrid_Calendar.css,WebGrid, Version=2.2.2.0, Culture=neutral, PublicKeyToken=683aa60800d9b3ae" rel="stylesheet" type="text/css" /> <link href="mvwres:50-WebGrid.Resources.WebGrid_Calendar.css,WebGrid, Version=2.2.2.0, Culture=neutral, PublicKeyToken=683aa60800d9b3ae" rel="stylesheet" type="text/css" /> <link href="mvwres:54-WebGrid.Resources.WebGrid_Calendar.css,WebGrid, Version=2.2.2.0, Culture=neutral, PublicKeyToken=683aa60800d9b3ae" rel="stylesheet" type="text/css" /> <link href="mvwres:17-WebGrid.Resources.WebGrid_Calendar.css,WebGrid, Version=2.2.2.0, Culture=neutral, PublicKeyToken=683aa60800d9b3ae" rel="stylesheet" type="text/css" /> <link href="mvwres:2-WebGrid.Resources.WebGrid_Calendar.css,WebGrid, Version=2.2.2.0, Culture=neutral, PublicKeyToken=683aa60800d9b3ae" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label_appli" runat="server" Font-Bold="True" Font-Names="GE Inspira" Font-Size="Large" Text="Label"></asp:Label><br /> <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="GE Inspira" Font-Size="16pt" ForeColor="ActiveCaption" Text="Gestion des Regularisations Comptables"></asp:Label><br /> <br /> <asp:Label ID="Label_message" runat="server" Font-Bold="True" Font-Names="GE Inspira" Font-Size="Large" ForeColor="Red" Text="Label" Visible="False"></asp:Label><br /> <asp:Label ID="Label_SSO" runat="server" Text="Label"></asp:Label> <asp:Panel ID="Panel_boutons" runat="server" BorderStyle="Solid" BorderWidth="2px" Height="50px" Width="944px"> <br /> <br /> <asp:Button ID="Button_all_demandes" runat="server" OnClick="Button_all_demandes_Click" Text="Toutes Mes demandes" Font-Bold="False" Width="152px" BackColor="InactiveCaptionText" BorderStyle="Solid" BorderWidth="1px" /> <asp:Button ID="Button_demandes_en_attente" runat="server" OnClick="Button_demandes_en_attente_Click" Text="Mes Demandes en attentes" Font-Bold="True" Width="184px" BackColor="InactiveCaptionText" BorderStyle="Solid" BorderWidth="1px" /> <asp:Button ID="Button_all_ddes" runat="server" OnClick="Button_all_ddes_Click" Text="Toutes Demandes" Width="136px" BackColor="InactiveCaptionText" BorderStyle="Solid" BorderWidth="1px" /> <asp:Button ID="Button_nouvelle_demande" runat="server" OnClick="Button_nouvelle_demande_Click" Text="Nouvelle Demande" Font-Bold="True" Width="136px" BackColor="InactiveCaptionText" BorderStyle="Solid" BorderWidth="1px" /> <asp:Button ID="Button_stats" runat="server" OnClick="Button_stats_Click" Text="Statistiques" BackColor="InactiveCaptionText" BorderStyle="Solid" BorderWidth="1px" /> <asp:Button ID="Button_acceuil" runat="server" Text="Accueil" BackColor="LightCyan" BorderStyle="Solid" BorderWidth="1px" /><br /> <asp:Label ID="Label4" runat="server" Font-Names="GE Inspira" Text="Classé par" Font-Italic="True"></asp:Label> <asp:DropDownList ID="DropDownList_tri" runat="server" Width="136px"> <asp:ListItem Value=" date_demande">Date</asp:ListItem> <asp:ListItem>Montant</asp:ListItem> <asp:ListItem Value="convert(nvarchar,Nature)">Nature</asp:ListItem> </asp:DropDownList> <asp:CheckBox ID="CheckBox_tri" runat="server" Font-Names="GE Inspira" Font-Size="10pt" Text="Décroissant" /><br /> </asp:Panel> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="True" CellPadding="4" Font-Names="GE Inspira" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="ID" OnPageIndexChanged="GridView1_PageIndexChanged" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="5" BorderStyle="Solid" BorderWidth="1px" AllowSorting="True"> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <SelectedRowStyle BackColor="#C5BBAF" ForeColor="#333333" BorderColor="Red" BorderStyle="Double" BorderWidth="2px" Font-Bold="True" /> <PagerStyle BackColor="InactiveCaption" ForeColor="White" HorizontalAlign="Center" Font-Bold="True" Font-Size="Small" /> <HeaderStyle BackColor="InactiveCaption" Font-Bold="True" ForeColor="Black" /> <AlternatingRowStyle BackColor="White" /> <RowStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" BackColor="InactiveCaptionText" /> <EditRowStyle BackColor="#7C6F57" /> <PagerSettings PageButtonCount="5" Position="Top" /> </asp:GridView> <asp:Button ID="Button_precedent" runat="server" Text=" - " /> <asp:Button ID="Button_suivant" runat="server" Text=" + " /><br /> <asp:Label ID="Label_ligne" runat="server" Text="Label" Visible="False"></asp:Label> <asp:Panel ID="Panel_details" runat="server" Height="184px" Width="808px" Visible="False" BackImageUrl="~/Images/fond_beige.jpg" BorderColor="#404040" BorderStyle="Solid" BorderWidth="1px" style="background-color: white" BackColor="WhiteSmoke"> <span style="font-family: GE Inspira"><strong><span style="background-color: #99ff66"> </span> </strong></span> <br /> <span style="font-family: GE Inspira"><strong> Numéro de demande</strong> </span> <asp:TextBox ID="TextBox_ID" runat="server" Font-Bold="True" Font-Names="GE Inspira" ReadOnly="True"></asp:TextBox><span style="font-family: GE Inspira"> Date de la demande</span><asp:TextBox ID="TextBox_date_demande" runat="server" ReadOnly="True"></asp:TextBox><span style="font-family: GE Inspira"> <br /> <br /> <strong> Accords</strong> </span> <asp:Label ID="Label2" runat="server" Font-Names="GE Inspira" Text="RSC"></asp:Label><span style="font-family: GE Inspira"> <asp:TextBox ID="TextBox_RSC" runat="server" Width="32px" ReadOnly="True"></asp:TextBox> </span> <asp:Label ID="Label3" runat="server" Font-Names="GE Inspira" Text="DIRECTEUR DES VENTES"></asp:Label> <asp:TextBox ID="TextBox_DV" runat="server" Width="32px" ReadOnly="True"></asp:TextBox> <span style="font-family: GE Inspira"> </span> <asp:Label ID="Label5" runat="server" Font-Names="GE Inspira" Text="DIRECTEUR FINANCIER"></asp:Label> <asp:TextBox ID="TextBox_DAF" runat="server" Font-Bold="True" Width="32px"></asp:TextBox><br /> <br /> <span style="font-family: GE Inspira"> <asp:Panel ID="Panel2" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="24px" Width="648px" BackColor="InactiveCaptionText"> Statut <asp:TextBox ID="TextBox_statut" runat="server" Font-Bold="True" Font-Names="GE Inspira" Font-Size="11pt" ForeColor="#FF0000" ReadOnly="True" Width="152px"></asp:TextBox><span style="font-family: GE Inspira"> Num de contrat </span> <asp:TextBox ID="TextBox_num_contrat" runat="server" ReadOnly="True"></asp:TextBox><span style="font-family: GE Inspira"> </span></asp:Panel> </span><span style="font-family: GE Inspira"> <br /> <asp:Panel ID="Panel3" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="24px" Width="648px" BackColor="InactiveCaptionText"> Immatriculation <asp:TextBox ID="TextBox_immatriculation" runat="server" ReadOnly="True"></asp:TextBox><span style="font-family: GE Inspira"> Client </span> <asp:TextBox ID="TextBox_Cust_nbr" runat="server" ReadOnly="True"></asp:TextBox> </asp:Panel> <br /> <asp:Panel ID="Panel4" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="24px" Width="648px" BackColor="InactiveCaptionText"> Montant <asp:TextBox ID="TextBox_Montant" runat="server" ReadOnly="True"></asp:TextBox><span style="font-family: GE Inspira"> Nature </span><asp:TextBox ID="TextBox_Nature" runat="server" ReadOnly="True"></asp:TextBox><span style="font-family: GE Inspira"> </span></asp:Panel> <br /> </span><br /><span style="font-family: GE Inspira"> </span> </asp:Panel> <br /> <br /> </div> </form> </body> </html>
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 '------------------------------------------------------------ 'CONNEXION SQL SERVER POUR RECEPTION ET SAUVEGARDE DES DONNEES Dim ds_sql As DataSet = New DataSet Dim da_sql As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter Dim maconnexion_sql As SqlClient.SqlConnection = New SqlClient.SqlConnection Dim connexion_string_sql As String Dim commande_sql As SqlClient.SqlCommand = New SqlClient.SqlCommand connexion_string_sql = "data source=FSEPAFRDTBS\SQLEXPRESS;Initial Catalog=Table_VHC_INVT;integrated security=true" maconnexion_sql.ConnectionString = connexion_string_sql maconnexion_sql.Open() 'activation du tri en décroissant Dim tri As String If CheckBox_tri.Checked Then tri = (" DESC") Else tri = ("") End If 'CHARGE LES NUMEROS DE DEMANDES commande_sql.Connection = maconnexion_sql commande_sql.CommandText = "select id,date_demande,statut from demandes ORDER BY " & DropDownList_tri.SelectedValue & tri 'création d'un adapter pour lui enregistrer toutes les nouvelles lignes d'un coup da_sql.SelectCommand = commande_sql da_sql.Fill(ds_sql, "SQL_TABLE_TEMP") GridView1.AutoGenerateColumns = True GridView1.Visible = True GridView1.DataSource = ds_sql.Tables("SQL_TABLE_TEMP") GridView1.DataBind() maconnexion_sql.Close() Panel_details.Visible = True
Partager