Bonjour,
Ma question est sans doute très bête mais après plusieurs heures de recherche, je ne vois toujours pas... Je précise que je débute tout juste en ASP.Net
J'ai une page web avec dessus, dans l'ordre: une Checkboxlist, 2 Listbox et 1 Gridview.
La Checkboxlist (countries) est alimentée par un "Select" sur une requête contenue dans une base Access. Idem pour les 2 Listbox2 (category et subcategory) et le Gridview, mais sur d'autres tables bien sûr.
En cliquant sur le bouton "Compare", je voudrais que le Gridview en dessous affiche les résultats du Select en prenant en compte les différents pays qui sont cochés dans la Checkboxlist.
Tout marche bien, sauf que le Gridview n'affiche les résultats que pour le premier pays coché, alors que je devrais avoir en résultat autant de lignes que de pays cochés.
Je ne vois pas comment récupérer les valeurs cochées et les envoyer en paramètres au Select dans le accessdatasource du Gridview pour au final simuler un "IN(pays1,pays2,...)".
Je suppose qu'il faut boucler quelque part sur le Gridview pour le relance autant de fois qu'il y a de pays cochés mais je ne vois pas comment!
Merci de toute aide
PS: le code est ci-dessous si ça peut aider à comprendre.
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 <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <p> <br /> <br /> <br /> <br /> <table> <tr> <td width="25%"> 1. Choose the countries to compare:</td> <td width="5%"> </td> <td width="70%"> 2. Choose the category</td> </tr> <tr> <td rowspan="3"> <asp:CheckBoxList ID="CB_list_countries" runat="server" DataSourceID="AccessDataSource1" DataTextField="country_label" DataValueField="country_id" Height="280px" Width="200px"> </asp:CheckBoxList> </td> <td rowspan="3"> </td> <td> <asp:ListBox ID="LB_cat" runat="server" AutoPostBack="True" DataSourceID="AccessDataSource2" DataTextField="category_label" DataValueField="category_id" Height="125px" Width="500px"></asp:ListBox> </td> </tr> <tr> <td> 3. Choose the subcategory</td> </tr> <tr> <td> <asp:ListBox ID="LB_subcat" runat="server" AutoPostBack="True" DataSourceID="AccessDataSource3" DataTextField="subcategory_label" DataValueField="subcategory_id" Height="125px" Width="500px"></asp:ListBox> </td> </tr> <tr> <td class="style2"> <asp:Button ID="Button1" runat="server" Text="Compare" /> </td> <td class="style2"> </td> <td class="style2"> </td> </tr> <tr> <td colspan="3"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="AccessDataSource4" ForeColor="#333333" GridLines="None" Width="805px"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns> <asp:BoundField DataField="country_label" HeaderText="country_label" SortExpression="country_label" /> <asp:BoundField DataField="Explanations" HeaderText="Explanations" SortExpression="Explanations" /> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> </table> </p> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/base_wp24.mdb" SelectCommand="SELECT * FROM [qry_countries_list]"></asp:AccessDataSource> <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/base_wp24.mdb" SelectCommand="SELECT * FROM [qry_categories]"></asp:AccessDataSource> <asp:AccessDataSource ID="AccessDataSource3" runat="server" DataFile="~/App_Data/base_wp24.mdb" SelectCommand="SELECT * FROM [categories] WHERE ([category_id] = ?)"> <SelectParameters> <asp:ControlParameter ControlID="LB_cat" Name="category_id" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:AccessDataSource> <asp:AccessDataSource ID="AccessDataSource4" runat="server" DataFile="~/App_Data/base_wp24.mdb" SelectCommand="SELECT [Explanations], [country_label] FROM [data_countries] WHERE (([category_id] = ?) AND ([subcategory_id] = ?) AND ([country_id] = ?))"> <SelectParameters> <asp:ControlParameter ControlID="LB_cat" Name="category_id" PropertyName="SelectedValue" Type="Int32" /> <asp:ControlParameter ControlID="LB_subcat" Name="subcategory_id" PropertyName="SelectedValue" Type="Int32" /> <asp:ControlParameter ControlID="CB_list_countries" Name="country_id" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:AccessDataSource> </asp:Content>
Partager