kindly fix this issue..
im trying to send email to selected users frm gridview using checkbox
im getting error in
string email =row.Cells[2].Text;
s.To.Add(email);
It cant the read the selected values in gridview...
source file-------------------
<%@ Page Language="C#" Debug="true" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
subject | |
| message |
aspx.cs file.........................................
protected void btnsubmit_Click(object sender, EventArgs e)
{
string id = string.Empty;
MailMessage s = new MailMessage();
s.From = new MailAddress("[email protected]");
s.Subject = txtsubject.Text;
s.Body = txtmessage.Text;
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chk = (CheckBox)row.FindControl("CheckBox1");
{
if (chk.Checked==true)
{
string email =row.Cells[2].Text;
s.To.Add(email);
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential p = new NetworkCredential();
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "********");
smtp.EnableSsl = true;
smtp.Send(s);
}
}
}
}
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Brijendra GautamPosted Mar 18, 2014, 5:15 AM
Label lblEmail = (Label) row.FindControl("lbl3");
string email = lblEmail.Text;