Click here to Skip to main content
15,896,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i sendig mail in asp.net it shows me in mail like thi s

DocName=css DropDownList4=System.Web.UI.WebControls.DropDownList


i have a dropdpwn in table when admin select any value from dropdown and click on submit button then value shown in mail like this what i want

DocName=css DropDownList4=2


code is
C#
 string DocName = ((Label)Repeater2.Items[i].FindControl("DocName")).Text;
                      string emailId = ((Label)Repeater2.Items[i].FindControl("YourEamil")).Text;
                      DropDownList dropdownvalue = ((DropDownList)Repeater2.Items[i].FindControl("DropDownList4"));

                      string docname = String.Empty;
                      string emailID = String.Empty;
                      string dropdownvalues = String.Empty;


// Next, we need to pass all three parameters to the email routine

                      if (DocName.ToString() != "")
                      {
                          docname = DocName.ToString();
                      }
                      else
                      {
                          docname = "Unavailable";
                      }
                         if (emailId.ToString() != "")
                      {
                          emailID = emailId.ToString();
                      }
                      else
                      {
                          emailID = "Unavailable";
                      }

                      if (dropdownvalue.SelectedItem.ToString() != "")
                      {
                          dropdownvalues = dropdownvalue.SelectedItem.ToString();
                      }
                      else
                      {
                          dropdownvalues = "Unavailable";
                      }
                   
                      //SendEmailUsingGmail(docname.ToString(), dropdownvalue.ToString(), emailId.ToString());
                      SendEmailUsingGmail(DocName.ToString(), emailId.ToString(), dropdownvalue.ToString());
                   
                     
                      cmd.ExecuteNonQuery();
                      
                      //try
                      //{
                      //    cmd.ExecuteNonQuery();
                      //    string emailId = ((Label)Repeater2.Items[i].FindControl("Label2")).Text;
                      //    SendEmailUsingGmail(string emailId);
                      //}
                      //catch (Exception ex)
                      //{
                      //    Supvisor.Text=(ex.Message);
                      //}
                      //try
                      //{

                      //    if (DropDownListcontrol != null)
                      //    {

                      //        if (DropDownListcontrol.SelectedValue == "1")
                      //        {

                      //            //get Current EMAIL_ID from the DataKey

                      //            string emailId = ((Label)Repeater2.Items[i].FindControl("Label2")).Text;
                      //            //write code to send mail
                      //            SendEmailUsingGmail(emailId);
                      //            dt.Clear();
                      //            dt.Dispose();
                      //        }
                      //        else if (DropDownListcontrol.SelectedValue == "3")
                      //        {
                      //        }
                      //    }
                      //}
                      //catch (Exception ex)
                      //{
                      //    Supvisor.Text = "Failed";
                      //}
                      //finally
                      //{
                      //    empId = string.Empty;
                      //}
                      
          

                          
           
                      //UPDATE APPPROVEID IN DOCUMENTINFO TABLE
                      //DMSLIB.Doc myDoc = new DMSLIB.Doc();
                      //myDoc.MarkDocAs(Convert.ToInt16(DocId.Text), Convert.ToInt32(DropDownListcontrol.SelectedValue));

                  }

              }
              else
              {
                  Supvisor.Text = "Error";
              }
              if (mySQLconnection.State == ConnectionState.Open)
              {
                  mySQLconnection.Close();
              }
           
                    }
        private void SendEmailUsingGmail(string DocName, string emailId, string dropdownvalue)
        {
            try
            {
                SmtpClient smtp = new SmtpClient();
                smtp.Credentials = new NetworkCredential("dfsdf4@gmail.com", "dsfsdf");
                smtp.Port = 587;
                smtp.Host = "smtp.gmail.com";
                smtp.EnableSsl = true;
                MailMessage message = new MailMessage();
                message.From = new MailAddress("dfsdf4@gmail.com");
                message.To.Add(emailId);
                //message.To.Add(New MailAddress(toEmailAddress));
                message.Subject = "DropDownList4" + dropdownvalue;
                message.Body = "DocName=" + DocName + " DropDownList4=" + dropdownvalue;
                //message.Subject = "Write your email subject here";
                //message.Body = "write the content of the email here";
                smtp.Send(message);
            }
            catch (Exception ex)
            {
                Response.Write("Error occured: " + ex.Message.ToString());
            }
        }
Posted
Updated 24-Nov-13 9:44am
v2
Comments
CHill60 24-Nov-13 15:43pm    
What is the problem?

1 solution

use
SQL
if (dropdownvalue.SelectedItem.ToString() != "")
                      {
                          dropdownvalues = dropdownvalue.SelectedValue.ToString();
                      }


in place of
SQL
if (dropdownvalue.SelectedItem.ToString() != "")
                      {
                          dropdownvalues = dropdownvalue.SelectedItem.ToString();
                      }
 
Share this answer
 

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