0

我创建了一个 htmlTable,我想通过电子邮件发送它:

Dim MyRow As New HtmlTableRow  
Dim cellCost, cellDisplayName, cellMoreInfo As New HtmlTableCell  
Dim tableAttributes As New HtmlTable  
tableAttributes.ID = "test"  

cellCost.InnerText = "$45.00"  
cellDisplayName.InnerText = "I am display Name"  
cellMoreInfo.InnerText = "I am more information"  

MyRow.Cells.Add(cellCost)  
MyRow.Cells.Add(cellDisplayName)  
MyRow.Cells.Add(cellMoreInfo)  

tableAttributes.Rows.Add(MyRow)  

PlaceHolder1.Controls.Add(tableAttributes)  

当试图通过电子邮件发送tableAttributes全局变量时......这就是我遇到麻烦的地方:
Message.Body = tableAttributes.anything<-失败。
如何创建一个动态生成的表,然后通过电子邮件发送它?

**更新 - 提供了解决方案
哈哈!成功了,你真棒。这是我根据您的建议创建的:

Dim SB As New StringBuilder()  
Dim SW As New StringWriter(SB)  
Dim htmlTW As New HtmlTextWriter(SW)  
Dim x As New HtmlTable  
x = Session("table")  
x.RenderControl(htmlTW)  

Dim sTable As String = SB.ToString()  

Response.Write("*" & sTable & "*") 
4

2 回答 2

1

使用对表的 Rendercontrol 分配将表导出到字符串编写器,从而生成可以包含在邮件中的字符串。

于 2012-01-21T23:03:21.903 回答
0

在生成这样的电子邮件时,我通常会跳到使用 XML Literals。我在http://www.thinqlinq.com/default/Creating-HTML-emails-using-VB-9-and-LINQ.aspx上写了一篇讨论这个的帖子。

于 2012-01-22T23:10:17.517 回答