Click here to Skip to main content
12,954,001 members (41,691 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 2:08am
Updated 30-Nov-12 2: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
OriginalGriff 6,464
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,020
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2017
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