[英]CheckBox disabled in asp.net
我正在尝试在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>
您是否已在数据库(要存储电子邮件的表)中插入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'
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.