0

我使用(C#)在后面的代码中填充我的gridview,我有一列称为[SO_Status],该列一开始是空的,我想在单击时将[SO_Status]的值更改为“SO已经发送”按钮发送!

这是我的网格视图的捕获: 在此处输入图像描述

选择代码是:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    Int16 email;
    if ( e.CommandName == "Select")
    {
        email = Convert.ToInt16(e.CommandArgument);
        em.Text = GridView1.Rows[email].Cells[4].Text;
    }
}
public void Send_Click(object sender, EventArgs e)
{
    if (FileUploadControl.HasFile)
    {
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.Host = "smtp.gmail.com";
        client.Port = 587;
        ....
        try
        {
            client.Send(msg);
            ClientScript.RegisterClientScriptBlock(this.GetType(), "validation", "alert('Your Email was sent successfully!');", true);       
        }
        catch
        {
            Response.Write("Sent error");
        }
    }
}

我使用选择按钮从线路中获取邮件地址并将电子邮件发送到此邮件地址,我想在发送此电子邮件后更改 SO_Status,以避免再次向同一个人发送电子邮件。

4

1 回答 1

0

您需要更新数据库中的 SO_Status 并从数据库重新绑定网格。

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        Int16 email;
        if ( e.CommandName == "Select")
        {
            email = Convert.ToInt16(e.CommandArgument);
            em.Text = GridView1.Rows[email].Cells[4].Text;
            //send the email
             if (Sendmail(em.Text))
             {
                updateStatus(em.Text);
                // rebind the grid. 
                bindgrid(); 
             }
             else
              {
               // write code to show error message.
              }
        }
    }






 private bool Sendmail( string email)
  {
    // code to send mail 
    // you can find the code on google.

   return returnvalue;
  }



 private void updateStatus(string email)
  {
    // Code to update db colomn
  }

   private void bindgrid()
  {
       // code to bind grid.
  }
于 2013-07-26T05:01:34.933 回答