Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 asp.net but i dont know how to write loop for gridview in the winodws application when user clicked checkbox


C#
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
Updated 30-Nov-12 2:10am
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900