Click here to Skip to main content
11,927,711 members (34,641 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#2.0 C#
I am using with C# windows forms.

i am binding gridview .

i want to use checkbox in gridview for select all Row Or Single Row (like gmail imbox) in gridview.

i want to send mail to all selected row. by clicking Send Mail button which is located outside the gridview

this is code used for but i dont know how to write loop for gridview in the winodws application when user clicked checkbox

protected void SendMail()
        string TotalMail;
        foreach (GridViewRow gvr in YourGridView.Rows)
            CheckBox chkMail = (CheckBox)gvr.Cells[0].FindControl("chkMail");
            Label lblMailId = (Label)gvr.Cells[1].FindControl("lblMailId ");
            if(chkMail.Checked == true)
                  TotalMail = TotalMail + lblColumn1.Text.ToString();
            objEmail          = new MailMessage();
            objEmail.To       = TotalMail;
            objEmail.From     = txtFrom.Text;
            objEmail.Subject  = "Test Email";
            objEmail.Body     = txtName.Text + ", " +
            objEmail.Priority = MailPriority.High;
  //SmtpMail.SmtpServer = "localhost";
    Response.Write("Your Email has been sent sucessfully - Thank You");
  catch (Exception exc){
    Response.Write("Send failure: " + exc.ToString());
Posted 30-Nov-12 3:08am
Edited 30-Nov-12 3:10am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100