Question

Im filling my gridview in the code behind using (C#), I have one column called [SO_Status], This column is empty at the begining, I want to change the value of [SO_Status] to "SO already sent" when I click the button Send!

here is a capture of my grid view: enter image description here

the select code is:

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");
        }
    }
}

I use the select button to get the mail address from the line and send email to this mail address, I want to change the SO_Status after sending this email, to avoid sending email another time to the same person.

Was it helpful?

Solution

You need to update the SO_Status in database and rebind the grid from database.

 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.
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top