Last post Aug 30, 2014 03:37 AM by demoninside9
Aug 21, 2014 08:23 AM|JunaidSagihr|LINK
Hello everybody i am new to asp.net .I have a scenario that ..
Gridview which is showing the customer information like ,"Cust_ID","Cust_Name","Email" and one checkbox with each row and send email button below the gridview .
I want to implement that when user select particular rows from gridview and press send email button.Email will go to the all selected users.
Aug 21, 2014 09:07 AM|santosh0288|LINK
On button_click event by using findcontrols in the method loop through all the checkbox controls and find the value is true or not.
if is true save all the respective emailId of that row into a list or a array and then loop through the list or a array and send the email by using sftp settings.
for example :(sending mail) you change the information according to your requirement:
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("email@example.com");
mail.Subject = "Test Mail";
mail.Body = "test mail body";
SmtpServer.Port = 587; // for gmail.
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;
Please try these steps it may help you.
Santosh Kumar Dash
Aug 21, 2014 11:02 AM|A2H|LINK
You need to look through the rows in Gridview and get the email address from selected rows based on checkbox selection.
Please see the sample code
protected void btnSendMail_Click(object sender, EventArgs e)
//Array list to hold selected email ids
ArrayList emailArray = new ArrayList();
//Looping through rows of GridView
foreach (GridViewRow gr in GridView1.Rows)
//Creating checkbox object using the find control method
CheckBox cb = (CheckBox)gr.FindControl("chkItem");
//Checking whether checkbox is checked or not
//If checked Adding email id to Arraylist
//Looping through the email id list
foreach (string email in emailArray)
//Set email user name - Change this as per your settings
const string username = "firstname.lastname@example.org";
//Set the email password - Change this as per your settings
const string password = "xxxxxxxxx";
SmtpClient smtpclient = new SmtpClient();
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
//Set the email from address of mail message - Change this as per your settings
MailAddress fromaddress = new MailAddress("email@example.com");
//Set the email smtp host - Change this as per your settings
smtpclient.Host = "smtp.gmail.com";
//Set the email client port - Change this as per your settings
smtpclient.Port = 587;
mail.From = fromaddress;
//Adding email id from array list as to address of email
//Set the email subject
mail.Subject = ("Test Subject");
mail.IsBodyHtml = true;
//Set the email body - Change this as per your logic
mail.Body = "This is test Mail";
smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpclient.Credentials = new System.Net.NetworkCredential(username, password);
Response.Write("<B>Email Has been sent successfully.</B>");
catch (Exception ex)
//Catch if any exception occurs
You can refer the below link for more details
Aug 30, 2014 03:37 AM|demoninside9|LINK
may this help you