2011-11-19 80 views
1

文檔我有一個GridView,它看起來像 發送電子郵件+ GridView控件

    ID  Filename  Type 
----------------------------------------------------- 
Share view  1  Tiger   .doc 
share view  2  Lion   .xls 
share view  3  dog    .ppt 

當我點擊視圖,文檔將被打開,我們可以對其進行編輯。我想分享鏈接執行一些特定的功能。如果我點擊共享,它應該要求輸入電子郵件,並將相應的文檔發送到寫入的電子郵件。防爆。如果我點擊文檔是老虎的共享,那麼該文檔應該發送到寫入的電子郵件。

+0

什麼是你的問題?你有什麼嘗試? – Oded

+0

我的問題是,當我點擊第一行的共享時,它應該要求我寫郵件,一旦我寫它,老虎文件應通過電子郵件發送到寫的地址。我怎樣才能做到這一點? – user662417

+0

好的,但你的問題到底是什麼?我如何區分哪個行被選中?或者我如何發送電子郵件?什麼是具體問題? – dasheddot

回答

1

我找到了解決方案。這裏使用了一段代碼。

在GridView中,對於份額超鏈接我用:

<asp:TemplateField> 
         <ItemTemplate> 
          <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"FileName","Share.aspx?FileName={0}") %>' 
            Text="Share"></asp:HyperLink> 
         </ItemTemplate> 
         </asp:TemplateField> 

在share.aspx頁

string datalink; 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     this.TextBox2.Text = Request.QueryString[0]; 
     datalink = this.TextBox2.Text; 
    } 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      // Create the mail message 
      string strFrom = "[email protected]"; 
      string strTo = TextBox1.Text; 
      string strCC = TextBox3.Text; 
      string strSubject = "Document shared"; 
      string strMsg = " The document has been shared with you. Please check the attachment."; 
      string myPath = @"C:\Visual Studio 2008\Data\"; 
      MailMessage objMailMsg = new MailMessage(strFrom, strTo); 

      objMailMsg.BodyEncoding = Encoding.UTF8; 
      objMailMsg.Subject = strSubject; 
      objMailMsg.Body = strMsg; 
      objMailMsg.CC.Add(strCC); 
      Attachment at = new Attachment(myPath + datalink); 
      objMailMsg.Attachments.Add(at); 
      objMailMsg.Priority = MailPriority.High; 
      objMailMsg.IsBodyHtml = true; 

      SmtpClient smtp = new SmtpClient(); 
      smtp.EnableSsl = true; 
      smtp.Send(objMailMsg); 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 

    }