Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
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 asp.net 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 + ", " +
                                txtComments.Text;
            objEmail.Priority = MailPriority.High;
  //SmtpMail.SmtpServer = "localhost";
  try{
    SmtpMail.Send(objEmail);
    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
v2

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

  Print Answers RSS
0 Afzaal Ahmad Zeeshan 256
1 OriginalGriff 251
2 BillWoodruff 240
3 Maciej Los 230
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
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