我在使用(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,以避免再次向同一个人发送电子邮件。
答案 0 :(得分: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.
}