asp.net - how to loop userControl c# -
i beginner in c # , have problem. here code of user control below
<%@ 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 grideditforminsertitem) ? "insert" : "update" %>' runat="server" commandname='<%# (container grideditforminsertitem) ? "performinsert" : "update" %>'></asp:button> <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 * typepartenaire" />
and in traitement.aspx page here fields being found in control .
newvalues["raisonsocial"] = (usercontrol.findcontrol("textbox9") textbox).text; newvalues["adresse"] = (usercontrol.findcontrol("textbox7") textbox).text; newvalues["codepostal"] = (usercontrol.findcontrol("textbox8") textbox).text; newvalues["presription"] = (usercontrol.findcontrol("textbox2") textbox).text; newvalues["raisonsocial2"] = (usercontrol.findcontrol("textbox10") textbox).text; newvalues["adresse2"] = (usercontrol.findcontrol("textbox11") textbox).text; newvalues["ville"] = (usercontrol.findcontrol("textbox4") textbox).text; newvalues["commentaires"] = (usercontrol.findcontrol("textbox1") textbox).text; newvalues["nombredekm"] = (usercontrol.findcontrol("textbox5") textbox).text; newvalues["groupe"] = (usercontrol.findcontrol("textbox6") textbox).text; newvalues["telephone"] = (usercontrol.findcontrol("homephonebox") radmaskedtextbox).text; newvalues["idtypepartenaire"] = (usercontrol.findcontrol("raddropdownlist1") 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"];
everything works , wish improve code , fields of user control dynamically via loop , example , make me code lines .
someone me . thank you
i think better declare properties in usercontrol hold values of textbox control.
example:
public string nombredekm { { return textbox5.text; } set { textbox5.text = value; } }
then in traitement.aspx page call
newvalues["nombredekm"] = usercontrol.nombredekm
Comments
Post a Comment