Asp.Net中按钮单击事件中的电子邮件
我发送邮件成功,但我希望在电子邮件中这样 文件名:abc 状态=批准 我在这张桌子上有一个下拉列表 现在在这里我想当管理员点击提交按钮,然后docname(像计划方法)和下拉列表值管理员选择(像批准/重新jct/挂起),例如,他选择拒绝,然后当用户收到邮件,他将能够看到这样的 docname:计划方法 状态:拒绝 这里是代码输入按钮Asp.Net中按钮单击事件中的电子邮件,asp.net,email,Asp.net,Email,我发送邮件成功,但我希望在电子邮件中这样 文件名:abc 状态=批准 我在这张桌子上有一个下拉列表 现在在这里我想当管理员点击提交按钮,然后docname(像计划方法)和下拉列表值管理员选择(像批准/重新jct/挂起),例如,他选择拒绝,然后当用户收到邮件,他将能够看到这样的 docname:计划方法 状态:拒绝 这里是代码输入按钮 protected void Button1_Click(object sender, EventArgs e) { stri
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
SqlConnection mySQLconnection = new SqlConnection(connStr);
string empId = string.Empty;
DataTable dt = new DataTable();
if (mySQLconnection.State == ConnectionState.Closed)
{
mySQLconnection.Open();
for (int i = 0; i < Repeater2.Items.Count; i++)
{
DropDownList DropDownListcontrol =
((DropDownList)Repeater2.Items[i].FindControl("DropDownList4"));
Label DocId = ((Label)Repeater2.Items[i].FindControl("DocId"));
SqlCommand cmd = new SqlCommand("approveddd", mySQLconnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@DocID", SqlDbType.Int).Value =
Convert.ToInt32((DocId.Text));
cmd.Parameters.Add("@ApproveID", SqlDbType.Int).Value =
Convert.ToInt32(DropDownListcontrol.SelectedValue);
cmd.Parameters.Add("@ApproveBy", SqlDbType.VarChar, 50).Value =
(Session["Login2"]);
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;
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(), emailId.ToString(),
dropdownvalue.ToString());
cmd.ExecuteNonQuery();
}
}
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("johkett@gmail.com", "123123120");
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
MailMessage message = new MailMessage();
message.From = new MailAddress("johkett@gmail.com");
message.To.Add(emailId);
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());
}
}
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
字符串connStr=
ConfigurationManager.ConnectionString[“mydms”]。ConnectionString;
SqlConnection mySQLconnection=newsqlconnection(connStr);
string empId=string.Empty;
DataTable dt=新的DataTable();
if(mySQLconnection.State==ConnectionState.Closed)
{
mySQLconnection.Open();
对于(int i=0;i
像这样,我想在电子邮件中看到
我是如何做到这一点的,而不是传递
dropdownvalues
,而是将控件作为字符串(dropdownvalues.ToString()
)传递
您应该更改此行:
SendEmailUsingGmail(DocName.ToString(), emailId.ToString(), dropdownvalue.ToString());
为此:
SendEmailUsingGmail(DocName, emailId, dropdownvalues);
另外,我建议从代码中删除不必要的ToString()
`按钮1\u Click'应如下所示:
protected void Button1_Click(object sender, EventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
SqlConnection mySQLconnection = new SqlConnection(connStr);
string empId = string.Empty;
DataTable dt = new DataTable();
if (mySQLconnection.State == ConnectionState.Closed)
{
mySQLconnection.Open();
for (int i = 0; i < Repeater2.Items.Count; i++)
{
DropDownList DropDownListcontrol = ((DropDownList)Repeater2.Items[i].FindControl("DropDownList4"));
Label DocId = ((Label)Repeater2.Items[i].FindControl("DocId"));
SqlCommand cmd = new SqlCommand("approveddd", mySQLconnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@DocID", SqlDbType.Int).Value = Convert.ToInt32((DocId.Text));
cmd.Parameters.Add("@ApproveID", SqlDbType.Int).Value = Convert.ToInt32(DropDownListcontrol.SelectedValue);
cmd.Parameters.Add("@ApproveBy", SqlDbType.VarChar, 50).Value = (Session["Login2"]);
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;
docname = !String.IsNullOrEmpty(DocName) ? DocName : "Unavailable";
emailId = !String.IsNullOrEmpty(emailID) ? emailID : "Unavailable";
dropdownvalues = !String.IsNullOrEmpty(dropdownvalue.SelectedValue) ? dropdownvalue.SelectedValue : "Unavailable";
SendEmailUsingGmail(docname, emailId, dropdownvalues);
cmd.ExecuteNonQuery();
}
}
else
{
Supvisor.Text = "Error";
}
if (mySQLconnection.State == ConnectionState.Open)
{
mySQLconnection.Close();
}
}
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
字符串connStr=ConfigurationManager.ConnectionString[“mydms”].ConnectionString;
SqlConnection mySQLconnection=newsqlconnection(connStr);
string empId=string.Empty;
DataTable dt=新的DataTable();
if(mySQLconnection.State==ConnectionState.Closed)
{
mySQLconnection.Open();
对于(int i=0;i