0

我正在尝试在 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>
4

1 回答 1

0

您是否在数据库(存储电子邮件的表)中插入了类似 isEmailsent 的列?(假设最初都是错误的)如果是,那么做这样的事情......

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' 
                }
            }
        }    
}
于 2013-11-13T06:49:07.267 回答