c# - Looping through TextBoxes and RadioButtonLists -


in webform have 6 textboxes , 6 radiobuttonlists:

now want send email visitor whatever have entered , clicked on radiobuttonlists. email part working fine, how should bind textboxes , radiobuttonlists string?

i have code far:

         protected void btnsubmit_click1(object sender, eventargs e)     {         //specify senders gmail address         string sendersaddress = "test@gmail.com";          //specify address want sent email to(can valid email address)         string receiversaddress = "test@gmail.com";          //specify password of gmial account u using sent mail(pw of sender@gmail.com)         const string senderspassword = "test";          //write subject of ur mail         const string subject = "testing items";           list<string> st1 = gettextboxesandradiobuttons();         //string body = gettextboxes();          try         {             //we use smtp client allows send email using smtp protocol             //i have specified properties of smtpclient smtp within{}             //gmails smtp server name smtp.gmail.com , port number 587             smtpclient smtp = new smtpclient             {                 host = "smtp.gmail.com",                 port = 587,                 enablessl = true,                 deliverymethod = smtpdeliverymethod.network,                 credentials = new networkcredential(sendersaddress, senderspassword),                 timeout = 3000             };              //mailmessage represents mail message             //it 4 parameters(from,to,subject,body)             mailmessage message = new mailmessage(sendersaddress, receiversaddress, subject, "test");             /*we use smtp sever specified above send message(mailmessage message)*/             smtp.send(message);             console.writeline("message sent successfully");             console.readkey();         }         catch (exception ex)         {             console.writeline(ex.message);          }     }       public list<string> returnlist = new list<string>();      private list<string> gettextboxesandradiobuttons()     {         string txt;          foreach (control ctr in page.controls)         {              callcontrols(ctr);          }          return returnlist;     }      private void callcontrols(system.web.ui.control p)     {         string returntext = "";          foreach (control ctrlmain in p.controls)         {             if (ctrlmain.hascontrols())             {                 /* recursive call */                 callcontrols(ctrlmain);             }             if (ctrlmain textbox)             {                 textbox txt;                 txt = (textbox)findcontrol(ctrlmain.id);                 returnlist.add(txt.text);             }             else if (ctrlmain radiobutton)             {                 radiobutton rad;                 rad = (radiobutton)findcontrol(ctrlmain.id);                 returnlist.add(rad.text);             }         }       } 

here markup ui:

<tr>         <td class="style4">             <asp:label id="label1" runat="server" text="1. "></asp:label>             <asp:textbox id="tbshoppinglist1" runat="server"></asp:textbox>         </td>         <td>             <asp:radiobuttonlist id="radiobuttonlist1" runat="server" height="16px"                  repeatdirection="horizontal" width="772px">                 <asp:listitem>cvs</asp:listitem>                 <asp:listitem>food lion</asp:listitem>                 <asp:listitem>home depot</asp:listitem>                 <asp:listitem>lowe`s</asp:listitem>                 <asp:listitem>publix</asp:listitem>                 <asp:listitem>target</asp:listitem>                 <asp:listitem>walgreens</asp:listitem>                 <asp:listitem>windixie</asp:listitem>                 <asp:listitem>walmart</asp:listitem>             </asp:radiobuttonlist>         </td>     </tr> 

similarly next 5 textboxes , radiobuttonlists!

this not working.

'st1' not storing in it.

this should both controls. can separate out logic in 2 different methods. recursively finds textboxes , radiobuttons withing page.controls. declare returnlist variable global (available both methods).

 public list<string> returnlist = new list<string>();  private list<string> gettextboxesandradiobuttons() {     string txt;      foreach (control ctr in page.controls)     {         callcontrols(ctr);      }  string finalstring = string.join(",", returnlist.toarray());     return returnlist; }  private void callcontrols(system.web.ui.control p) {     string returntext = "";      foreach (control ctrlmain in p.controls)     {         if (ctrlmain.hascontrols())         {             /* recursive call */             callcontrols(ctrlmain);         } if (ctrlmain textbox)                 {                     textbox txt = (textbox)ctrlmain;                     //txt = (textbox)findcontrol(ctrlmain.uniqueid);                     returnlist.add(txt.text);                 }                 else if (ctrlmain radiobuttonlist)                 {                     radiobuttonlist rad = (radiobuttonlist)ctrlmain;                     //rad = (radiobuttonlist)findcontrol(ctrlmain.uniqueid);                     returnlist.add(rad.selectedvalue);                 }     }   } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -