Bonjour je développe en C# et par soucis d'amélioration de mon code je voudrais réaliser certaines actions liées à l'utilisation de mon contrôle utilisateur dans une boucle, mais j'ignore comment m'y prendre.

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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//Webcontrole.ascx
 
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="JorgesAppli.WebUserControl1" %>
 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
 
<table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"
    style="border-collapse: collapse;">
    <tr class="EditFormHeader">
        <td colspan="2">
            <b>Enregistrer un nouveau partenaire</b>
        </td>
    </tr>
    <tr>
        <td>
            <table id="Table3" width="450px" border="0" class="module">
                <tr>
                    <td>Raison sociale 1:</td>
                     <td>
                         <asp:TextBox ID="TextBox9" Text='<%# Bind( "RaisonSocial") %>' runat="server" TabIndex="8">
                        </asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Adresse :
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox7" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Adresse") %>'>
                        </asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Code postal:
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox8" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CodePostal") %>'>' TabIndex="1">
                        </asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Type partenaire:
                    </td>
                    <td>
                        <telerik:RadDropDownList ID="RadDropDownList1" runat="server" DropDownHeight="200px" Width="226px" Skin="Default"
                            DefaultMessage="Sélectionnez le type de partennaires" DropDownWidth="226px"
                            DataValueField="IdTypePartenaire" DataTextField="Description" DataSourceID="SqlDataSource2" AutoPostBack="true">
                        </telerik:RadDropDownList>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <b>SLE :</b>
                    </td>
                </tr>
                <tr>
                    <td>Prescription CE :
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox2" Text='<%# Bind( "Presription") %>' runat="server" TabIndex="8">
                        </asp:TextBox>
                    </td>
                </tr>
 
                <tr>
                    <td>Raison sociale 2:
                    </td>
                    <td>
                         <asp:TextBox ID="TextBox10" Text='<%# Bind( "RaisonSocial2") %>' runat="server" TabIndex="8">
                        </asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Adresse(2):
                    </td>
                    <td>
                         <asp:TextBox ID="TextBox11" Text='<%# Bind( "Adresse2") %>' runat="server" TabIndex="8">
                        </asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Ville :
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox4" Text='<%# DataBinder.Eval(Container, "DataItem.Commentaires") %>' runat="server" TabIndex="11">
                        </asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Téléphone :
                    </td>
                    <td>
                        <telerik:RadMaskedTextBox ID="HomePhoneBox" runat="server" SelectionOnFocus="SelectAll"
                            Text='<%# DataBinder.Eval(Container, "DataItem.Telephone") %>' PromptChar="_" Mask="(###) ###-####"
                            TabIndex="3">
                        </telerik:RadMaskedTextBox>
                    </td>
                </tr>
            </table>
        </td>
        <td style="vertical-align: top">
            <table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0" class="module">
                <tr>
                    <td>Commentaires :
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="TextBox1" Text='<%# DataBinder.Eval(Container, "DataItem.Commentaires") %>' runat="server" TextMode="MultiLine"
                            Rows="5" Columns="40" TabIndex="5">
                        </asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Groupe :
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="TextBox6" Text='<%# DataBinder.Eval(Container, "DataItem.Groupe") %>' runat="server" TextMode="MultiLine"
                            Rows="2" Columns="40" TabIndex="6">
                        </asp:TextBox>
                    </td>
                </tr>
 
                 <tr>
                    <td>Nombre de Kms :
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="TextBox5" Text='<%# DataBinder.Eval(Container, "DataItem.NombreDeKm") %>' runat="server" TextMode="MultiLine"
                            Rows="2" Columns="40" TabIndex="6">
                        </asp:TextBox>
                    </td>
                </tr>
 
 
                 <tr>
                    <td>Actif  :
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:RadioButtonList ID="RadioButtonList1" runat="server" TabIndex="2" RepeatDirection="Horizontal" BorderStyle="None" Width="191px">
                                    <asp:ListItem Text="Oui" Selected="True"></asp:ListItem>
                                    <asp:ListItem Text="Non"></asp:ListItem>
                                </asp:RadioButtonList>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td colspan="2"></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td align="right" colspan="2">
            <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>&nbsp;
                                    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                        CommandName="Cancel"></asp:Button>
        </td>
    </tr>
</table>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="Data Source=CDEV01;Initial Catalog=test;Integrated Security=True" SelectCommand="SELECT * FROM TypePartenaire" />
 
 
et dans une autre page qui s'appelle traitement.aspx je récupère les éléments qui se trouvent sur dans mon contrôle utilisateur. Tout ceci marche bien, mais dans un soucis d'optimisation de mon code j'aimerai savoir s'il n'est pas possible d'utiliser une boucle pour faire le travail, et si oui comment.
 
 
//Traitement.aspx
 
newValues["RaisonSocial"] = (userControl.FindControl("TextBox9") as TextBox).Text;
                        newValues["Adresse"] = (userControl.FindControl("TextBox7") as TextBox).Text;
                        newValues["CodePostal"] = (userControl.FindControl("TextBox8") as TextBox).Text;
                        newValues["Presription"] = (userControl.FindControl("TextBox2") as TextBox).Text;
                        newValues["RaisonSocial2"] = (userControl.FindControl("TextBox10") as TextBox).Text;
                        newValues["Adresse2"] = (userControl.FindControl("TextBox11") as TextBox).Text;
                        newValues["Ville"] = (userControl.FindControl("TextBox4") as TextBox).Text;
                        newValues["Commentaires"] = (userControl.FindControl("TextBox1") as TextBox).Text;
                        newValues["NombreDeKm"] = (userControl.FindControl("TextBox5") as TextBox).Text;
                        newValues["Groupe"] = (userControl.FindControl("TextBox6") as TextBox).Text;
                        newValues["Telephone"] = (userControl.FindControl("HomePhoneBox") as RadMaskedTextBox).Text;
                        newValues["IdTypePartenaire"] = (userControl.FindControl("RadDropDownList1") as RadDropDownList).SelectedValue;
                        //Affectation des dites valeurs
                        String RaisonSocial = (String)newValues["RaisonSocial"];
                        String Adresse = (String)newValues["Adresse"];
                        String Presription = (String)newValues["Presription"];
                        String RaisonSocial2 = (String)newValues["RaisonSocial2"];
                        int CodePostal = int.Parse(newValues["CodePostal"].ToString());
                        int IdTypePartenaire = int.Parse(newValues["IdTypePartenaire"].ToString());
                        String Adresse2 = (String)newValues["Adresse2"];
                        String Ville = (String)newValues["Ville"];
                        String Commentaires = (String)newValues["Commentaires"];
                        String NombreDeKm = (String)newValues["NombreDeKm"];
                        String Groupe = (String)newValues["Groupe"];
                        String Telephone = (String)newValues["Telephone"];