asp.net - Send Email List c# -


i have page "folder access" , 1 checkbox.

today, in .cs, each checkbox checked in folder access, send email owner of folder. email, create in page hiddenfield email.

but, now, have more 1 owner each folder. if continues way, have duplicate rows. how can list email each folder?

my .aspx

<columns>     <asp:boundfield datafield="folderaccess" headertext="folder access" />     <asp:templatefield>         <itemtemplate>             <asp:checkbox id="checkbox1" runat="server" text="access read" oncheckedchanged="checkbox1_changecheck"                 autopostback="true" />             <asp:hiddenfield id="email" runat="server" value='<%# bind("email") %>' />         </itemtemplate>     </asp:templatefield> </columns> 

my .cs

public class listrequest {     public string email { get; set; }     public string folderaccess { get; set; } }  public list<listrequest> preenchevalores(sqldatareader reader) {     var lista = new list<listrequest>();     while (reader.read())     {         var listrequest = new listrequest();          listrequest.email = reader["email"].tostring();         listrequest.folderaccess = reader["folderaccess"].tostring();         lista.add(listrequest);     }     return lista; }   public list<listrequest> consultarrequest() {     var lstretorno = new list<listrequest>();     using (objconexao = new sqlconnection(strstringconexao))     {         using (objcommand = new sqlcommand(strselectporid, objconexao))         {             try             {                 objconexao.open();                 var objdatareader = objcommand.executereader();                 if (objdatareader.hasrows)                     lstretorno = preenchevalores(objdatareader);             }             catch (exception ex)             {                 throw new exception(ex.message);             }                         {                 objconexao.close();             }         }     }     return lstretorno; }  protected void btnsend_onclick(object sender, eventargs e) {     foreach (gridviewrow row in gridview.rows)     {         checkbox check = (checkbox)row.findcontrol("checkbox1");         hiddenfield hd1 = (hiddenfield)row.findcontrol("email");         string email = hd1.value.tostring();          if (check.checked == true)         {              system.net.mail.mailmessage objemail = new system.net.mail.mailmessage();             objemail.from = new mailaddress("caio.jesus@br.com", "xxx");             objemail.to.add(email);             objemail.priority = system.net.mail.mailpriority.high;             objemail.isbodyhtml = true;             objemail.subject = "system ndrsecurity - novas requisições.";             objemail.body = "test";             objemail.subjectencoding = encoding.getencoding("iso-8859-1");             objemail.bodyencoding = encoding.getencoding("iso-8859-1");             smtpclient objsmtp = new smtpclient("xxx");             objsmtp.enablessl = true;             objsmtp.port = 25;             objsmtp.credentials = new networkcredential("caio.jesus@br.com", "xxx");             objsmtp.send(objemail);         }     }      response.redirect("home.aspx"); } 

i suppose make listrequest object contain list of email addresses. hidden field contain list.

public class listrequest {     public list<string> emailaddresses { get; set; }     public string folderaccess { get; set; } } 

then you'd have change onlcick loop on values in hd1 variable.

if (check.checked == true) {     foreach(string email in (list<string>hd1.value))     {         system.net.mail.mailmessage objemail = new system.net.mail.mailmessage();         objemail.from = new mailaddress("caio.jesus@br.com", "xxx");         objemail.to.add(email);         objemail.priority = system.net.mail.mailpriority.high;         objemail.isbodyhtml = true;         objemail.subject = "system ndrsecurity - novas requisições.";         objemail.body = "test";         objemail.subjectencoding = encoding.getencoding("iso-8859-1");         objemail.bodyencoding = encoding.getencoding("iso-8859-1");         smtpclient objsmtp = new smtpclient("xxx");         objsmtp.enablessl = true;         objsmtp.port = 25;         objsmtp.credentials = new networkcredential("caio.jesus@br.com", "xxx");         objsmtp.send(objemail);     } } 

Comments