Bonjour;

Eh oui un n.ième cas de liste déroulante dans un GridView ...
Petite spécificité : la liste déroulante présente sur chaque ligne du tableau doit avoir un contenu distinct ... et je galère là-dessus.

Avant de décrire mon pb, voici mon modèle de données (3 tables), qui permet de gérer des droits d'accès utilisateur à nos différentes applications :

Table GNAppz : table contenant nos différentes applis
- id (clef primaire)
- name

Table GNLevels : table contenant les niveaux d'accès possibles pour chaque appli (chacune ayant un nombre de niveaux possibles différents)
- appid (clef étrangère provenant de GNAppz.id)
- applevel (niveau d'accès pour cette appli)
- applabel (libellé de l'accès pour cette appli et ce niveau )
Clef aggrégée : [appid,applevel]

Exemple de valeurs pour l'appli d'id 1 :
(1,0,'Consultation')
(1,1,'Edition')
(1,2,'Administration')

Table GNRights : droits des utilisateurs pour chaque appli
- ipn (identifiant utilisateur unique)
- appid
- applevel
Clef aggrégée : [ipn,appid]

Bon maintenant, mon pb :

J'ai une permière combo qui me permet de sélectionner un user.
Dans mon GridView, j'affiche le droit actuel de l'utilisateur pour chaque appli (ça, ça marche). Par contre, quand je passe en édition sur la ligne d'une appli, je n'arrive pas à populer le dropdown avec la liste des droits possibles pour cette appli En plus, il faudrait que la valeur sélectionnée du dropdown soit bien celle dudit utilisateur ... Bref je galère (depuis des jours ! )

Voici mon 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
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
    <form id="form1" runat="server">

        <!-- Définition des DataSources -->

        <asp:SqlDataSource ID="UsersDS" runat="server" ConnectionString="<%$ ConnectionStrings:SMU_DEVConnectionString %>" SelectCommand="SELECT firstname + ' ' + lastname as name, ipn FROM XRUserInfo WHERE ipn IN (SELECT DISTINCT ipn FROM GnRights) ORDER BY lastname, firstname"></asp:SqlDataSource>

        <asp:SqlDataSource ID="AccesDS" runat="server" ConnectionString="<%$ ConnectionStrings:SMU_DEVConnectionString %>" 
            SelectCommand="SELECT DISTINCT [applabel] FROM [GNLevels] WHERE ([appid] = @appid)">
            <SelectParameters>
                <asp:ControlParameter ControlID="UserAppsGridView" Name="appid" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:SqlDataSource ID="UserAppsDS" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SMU_DEVConnectionString %>" 
            SelectCommand="SELECT id as 'appid',name, GNLevels.applabel
                           FROM GNAppz
                           INNER JOIN GNLevels ON GNLevels.appid = GNappz.id
                           INNER JOIN GNRights ON (GNRights.appid = GNAppz.id AND GNRights.applevel = GNLevels.applevel AND GNRights.ipn=@ipn)
                           ORDER BY id
                           " 
            UpdateCommand="UPDATE [GNRights] SET [applevel] = @applevel WHERE [ipn] = @ipn AND [appid] = @appid">
            <SelectParameters>
                <asp:ControlParameter ControlID="UsersDropDown" Name="ipn" PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="applevel" Type="Int32" />
                <asp:Parameter Name="ipn" Type="String" />
                <asp:Parameter Name="appid" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>

        <!-- Définition de l'interface -->

        <asp:DropDownList ID="UsersDropDown" runat="server" DataSourceID="UsersDS" DataTextField="name" DataValueField="ipn" AutoPostBack="True"></asp:DropDownList>
        
        <br /><br />
        
        <asp:GridView ID="UserAppsGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="appid" DataSourceID="UserAppsDS">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="appid"   HeaderText="appid"   ReadOnly="True" SortExpression="appid" InsertVisible="False" />
                <asp:BoundField DataField="name" HeaderText="name" ReadOnly="True" SortExpression="name" />
                
                <asp:TemplateField HeaderText="applabel" SortExpression="applabel">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="AppDS" DataTextField="applabel" DataValueField="applevel"></asp:DropDownList>
                        <asp:SqlDataSource ID="AppDS" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:SMU_DEVConnectionString %>" 
                            SelectCommand="SELECT applabel,applevel FROM GNLevels WHERE appid = 1">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="UserAppsGridView" Name="appid" PropertyName="SelectedValue" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("applabel") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                
            </Columns>
        </asp:GridView>

    </form>
Pas glop ... Une idée ?

Merci à tous/toutes

Olivier