我正在尝试在asp.net中发送邮件。管理员发送邮件到相应的电子邮件ID然后管理员检查复选框并发送电子邮件,此后我想显示复选框禁用这是我想要的,因为当管理员再次登录然后他将无法再次检查相同的复选框因为邮件已经发送,当新电子邮件到来时,必须启用复选框,因为管理员仍然没有在新电子邮件中执行任何检查......
在我的项目中..当我勾选复选框并点击提交按钮然后发送电子邮件但是当管理员再次登录然后检查新记录是否出现然后上一个复选框始终启用但我想在之前禁用复选框记录,因为电子邮件已经发送..
像这样emalid
john_11@gmail.com (this is new record then check box enabled)
kety_45@yahoo.com ( admin already check in this and mail send then check box must be
disabled)
这是代码按钮代码
protected void btnSendMail_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["email"].ConnectionString;
SqlConnection mySQLconnection = new SqlConnection(connStr);
string empId = string.Empty;
DataTable dt = new DataTable();
try
{
mySQLconnection.Open();
for (int i = 0; i < Repeateremail.Items.Count; i++)
{
CheckBox checkboc =
((CheckBox)Repeateremail.Items[i].FindControl("chkSelect"));
if (checkboc != null)
{
if (checkboc.Checked == true)
{
string emailId =
((Label)Repeateremail.Items[i].FindControl("lbl_email")).Text;
SendEmailUsingGmail(emailId);
dt.Clear();
dt.Dispose();
}
}
}
}
catch (Exception ex)
{
emailsent.Text="Failed";
}
finally
{
empId = string.Empty;
}
}
这是html
<td>
Email
</td>
<td>
Check
<asp:CheckBox ID="chkSelectAll"
runat="server"
AutoPostBack="true"
OnCheckedChanged="chkSelectAll_CheckedChanged"/>Send
Mail To All ?
</td>
</tr>
<td>
<asp:Label Id="lbl_email" runat="server"
Text='<%#DataBinder.Eval(Container.DataItem, "UserEmail")%>'>
</asp:Label>
</td>
<td>
<asp:CheckBox ID="chkSelect"
runat="server"/>
</td>
答案 0 :(得分:0)
您是否在数据库中插入了isEmailsent like列(您存储电子邮件的表)? (假设最初都是假的) 如果是,那就做这样的事......
void OnButtonCliked(object sender, eventargs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["email"].ConnectionString;
SqlConnection mySQLconnection = new SqlConnection(connStr);
string empId = string.Empty;
DataTable dt = new DataTable();
try
{
mySQLconnection.Open();
for (int i = 0; i < Repeateremail.Items.Count; i++)
{
CheckBox checkboc =
((CheckBox)Repeateremail.Items[i].FindControl("chkSelect"));
if (checkboc != null)
{
if (checkboc.Checked == true)
{
string emailId =
((Label)Repeateremail.Items[i].FindControl("lbl_email")).Text;
//you should do something here..like
string query = "update loginTable set isEmailSent = 'true' where email = emailID";
//execute the query here...
SendEmailUsingGmail(emailId);
dt.Clear();
dt.Dispose();
//then use Repeater bind to bind the data...and in repeater bind function you can get the value of checkbox and then set the Repeaeteremail.Items checkboxes to the values updated above
}
else if (checkboc.Checked == false )
{
//do samething as above just update the string with isEmailSent = 'false'
}
}
}
}