开发者

control if email was already checked in gridview

开发者 https://www.devze.com 2023-02-25 06:11 出处:网络
I\'ll define the problem first. I have a gridview which has a column checkboxes and another column email adresses. If for example I select 3 rows out of 7 and these 3 rows have all the same email addr

I'll define the problem first. I have a gridview which has a column checkboxes and another column email adresses. If for example I select 3 rows out of 7 and these 3 rows have all the same email address, my code will send 3 emails to the address. Is it possible to get these 3 rows in 1 mail?

My current code looks like this:

for (int i = 0; i < GridView1.Rows.Count; i++)
{
    CheckBox ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBoxATH");

    if (ck != null)
    {
   Label lblUsrE = (Label)GridView1.Rows[i].Cells[7].FindControl("LabelEmail");
     开发者_StackOverflow中文版  string emadr = lblUsrE.Text.ToString();

   if (ck.Checked == true)
       {
      MailMessage mail = new MailMessage();
          mail.To.Add(emadr.ToString());
       }}}

I was thinking of another loop around lblUsrE, but I could use some help here.

Regards Mati


List<string> lst = new List<string>();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
    CheckBox ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBoxATH");
    if (ck != null)
    {
      Label lblUsrE = (Label)GridView1.Rows[i].Cells[7].FindControl("LabelEmail");
      string emadr = lblUsrE.Text.ToString();
      if (ck.Checked == true && !lst.Contains(emadr))
      {
        lst.Add(emadr);
        MailMessage mail = new MailMessage();
        mail.To.Add(emadr.ToString());
        ....
       }
     }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消