2013-07-26 25 views
0

在使用(C#)後面的代碼填充我的gridview中的代碼後,我有一列名爲[SO_Status],這個列在開始時是空的,我想改變當我點擊Send按鈕時,[SO_Status]爲「SO已發送」的值。在點擊按鈕後在gridview中選擇的行添加列值發送

這裏是我的網格視圖的捕捉: enter image description here

選擇代碼:

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

您需要更新數據庫中的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. 
    } 
+0

Querry的更新應該如何? – tollamie

+0

update [「tablename」] set SO_Status = [「value」]其中email = [「email」]你需要用你的數據庫表名「value」替換爲「true」或false,或者什麼類型的db列和「電子郵件」以及您發送電子郵件的電子郵件地址。 –

+0

我編輯了我的答案,請現在檢查。 –

相關問題