Reputation: 89
I have created an htmlTable and I want to email it:
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)
When trying to email the tableAttributes
global variable ... well that's where I run into troubles:
Message.Body = tableAttributes.anything
<- fails.
How can I create a dynamically generated table and then email it?
**UPDATE - solution was provided
Ha ha! it worked, you're awesome. This is what I created from your advice:
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 & "*")
Upvotes: 0
Views: 2478
Reputation: 10418
When generating emails like this, I typically leap to use XML Literals. I wrote up a post discussing this at http://www.thinqlinq.com/default/Creating-HTML-emails-using-VB-9-and-LINQ.aspx.
Upvotes: 0
Reputation: 76
Use the Rendercontrol assignment to the table to export the table to a stringwriter which results in a string that can be included in your mail.
Upvotes: 1