在GridView中获取指定的数字到行

时间:2014-03-11 05:41:11

标签: c# asp.net email gridview

我在GridView中有一个导入的excelsheet。现在我要向所有记录发送电子邮件,但是在从网格视图中选择前10条记录之后,将以电子邮件的方式发送,当流程完成后,电子邮件将再次发送到接下来的10条记录,依此类推。 / p>

以下是我的代码:

void Send_Mail()
    {
        try
        {
            string Pass, FromEmailid, HostAdd;

            foreach (GridViewRow gr in DataGridView.Rows)
            {
                HostAdd = ConfigurationManager.AppSettings["Host"].ToString();
                FromEmailid = ConfigurationManager.AppSettings["FromMail"].ToString();
                Pass = ConfigurationManager.AppSettings["Password"].ToString();

                Label LblName = gr.FindControl("LblName") as Label;
                Label LblMail = gr.FindControl("LblEmail") as Label;

                string Name = LblName.Text;
                string Mail = LblMail.Text;
                string subject = TxtSubject.Text;

                SmtpClient client = new SmtpClient();
                MailMessage msg = new MailMessage();

                NetworkCredential credentials = new NetworkCredential(FromEmailid, Pass);

                client.Host = HostAdd;
                client.Port = 25;
                client.UseDefaultCredentials = false;
                client.Credentials = credentials;
                client.EnableSsl = true;
                MailAddress from = new MailAddress(FromEmailid);
                msg.IsBodyHtml = true;
                msg.Subject = subject;
                msg.Body = ReadTemplate(Name);
                msg.To.Add(Mail);
                msg.From = from;

                client.Send(msg);
                LblMessage.Text = "Email Send Successfully";
                LblMessage.Visible = true;
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

这里你没有提到你真正需要的东西。是否需要发送不同的邮件或其他东西.... 你可以试试这样的东西

void Send_Mail()
    {
        try
        {
             int rowCount = 0; 
            string Pass, FromEmailid, HostAdd;

            foreach (GridViewRow gr in DataGridView.Rows)
            {
                rowCount++;
                if(rowCount == 10)
                  {
                     SendMail1();
                  }
                else if (rowCount == 20)
                  {
                      SendMail2();
                   }

            }
        }
    }

注意:这不是一个确切的答案。所以尝试通过应用这个来做某事。