Bonjour à tous,

Je rencontre des difficultés sur le développement d'une application en ASP.

J'ai créé une list view qui récupère des données et sur laquelle j'ai mis en place le modification et l'insertion.

J'ai voulu remplacer les champs texte par des dropdownlist mais malheureusement ceux-ci me bloquent en insertion.

Ces deux dropdownlist récupèrent des valeurs à partir de deux autres requêtes et la seconde se base sur la résultat de la première pour sélectionner ses valeurs.

L'affichage des valeurs se fait correctement. Par contre j'ai l'impression que le selected value conserve sa valeur initiale

Lors de l'insertion j'ai une erreur me disant impossible d'insérer des valeurs NULL (et je ne souhaite pas insérer des valeurs null dans ma base) pour le champ IdComposantDommage

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
 <asp:TextBox ID="IDJournal" runat="server"></asp:TextBox>
      <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SAV IMERIRConnectionString %>" 
            DeleteCommand="DELETE from Incidents where Incidents.id = @IdIncident" 
            InsertCommand="INSERT INTO INCIDENTS (IdAffaire, Principal, Commentaires, IdComposantDommage) VALUES (@IDJournal,  @Principal, @Commentaires, @IdComposantDommage)"
            SelectCommand="SELECT Incidents.Id as IdIncident, Composant.Designation as Composant, Composant.Id as IdComposant,Dommage.Id as IdDommage, Dommage.Description as Dommage,ComposantDommage.id as IdComposantDommage, Incidents.Principal, Incidents.Commentaires FROM Incidents,ComposantDommage,Composant, Dommage Where Dommage.Id = ComposantDommage.Id AND Incidents.IdComposantDommage = ComposantDommage.Id AND ComposantDommage.IdComposant = Composant.Id AND Incidents.IdAffaire = @IDJournal order by Principal DESC" 
            UpdateCommand="UPDATE Incidents SET IdComposantDommage = @IdComposantDommage, Principal = @Principal, Commentaires =@Commentaires where Id = @IdIncident">
        <InsertParameters>
            <asp:ControlParameter ControlID="IDJournal" Name="IDJournal" Type="Int32" /> 
            <asp:Parameter Name="Principal" />
            <asp:Parameter Name="Commentaires" />
             <asp:ControlParameter ControlID="ListView1" Name="IdComposantDommage" PropertyName="SelectedDataKey[1]"
                Type="Int32" />
        </InsertParameters>
        </asp:SqlDataSource>
         <asp:SqlDataSource ID="Composants" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SAV IMERIRConnectionString %>" 
            SelectCommand="SELECT Id as IdComposant, Designation as IntituleComposant FROM Composant UNION SELECT NULL, NULL" 
            ProviderName="<%$ ConnectionStrings:SAV IMERIRConnectionString.ProviderName %>">
        </asp:SqlDataSource>
      <asp:ListView ID="ListView1" runat="server" ConvertEmptyStringToNull="False" 
            DataKeyNames="IdIncident,IdComposantDommage"
            DataSourceID="SqlDataSource1" InsertItemPosition="LastItem">
            <InsertItemTemplate>
            <asp:SqlDataSource ID="DommageComposants" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SAV IMERIRConnectionString %>" 
            SelectCommand="SELECT Dommage.Description as IntituleDommage, Dommage.Id as IdDommage, ComposantDommage.Id as IdComposantDommage FROM [dbo].[Dommage] INNER JOIN ComposantDommage ON ComposantDommage.IdDommage = Dommage.Id  Where ComposantDommage.IdComposant = @Composant UNION SELECT null, 0, 0">
            <SelectParameters>
                <asp:ControlParameter ControlID="Composant" Name="Composant" 
                PropertyName="SelectedValue" />
            </SelectParameters>
        </asp:SqlDataSource>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="CancelButton" runat="server" CommandName="Cancel" 
                            ImageUrl="~/Images/s_cancel.png" width="12px" Height="12px"/>&nbsp;
                            <asp:ImageButton ID="InsertButton" runat="server" CommandName="Insert" 
                            ImageUrl="~/Images/s_success.png" width="12px" Height="12px"/>
                    </td>
                    <td>
                         <asp:Label ID="IdIncidentLabel" runat="server" /></td>
                    <td>
                        <asp:DropDownList ID="Composant" runat="server" 
                            DataSourceID="Composants" DataTextField="IntituleComposant" 
                            DataValueField="IdComposant"
                            Width="100%" AutoPostBack="True">
                        </asp:DropDownList>
                    </td>
                    <td>
                        <asp:DropDownList ID="IdComposantDommage" runat="server" 
                            DataSourceID="DommageComposants" DataTextField="IntituleDommage" 
                            DataValueField="IdComposantDommage" AutoPostBack="True"
                            Width="100%">
                        </asp:DropDownList>
                    </td>
                    <td>
                        <asp:CheckBox ID="PrincipalCheckBox" runat="server" 
                            Checked='<%# Bind("Principal") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="CommentairesTextBox" runat="server" 
                            Text='<%# Bind("Commentaires") %>' />
                    </td>
                </tr>
            </InsertItemTemplate>
        </asp:ListView>
Merci d'avance pour vos réponses