Emailing a GridView

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

I am trying to email a GridView saved as html but all I am getting is
"System.Web.UI.HtmlTextWriter" in the Body of the email. Below is my code.
Any help is appreciated.
-David

Protected Sub BtnEmailPlanner_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim gv As GridView = gvWeeklyPlanner
Dim SB As New StringBuilder()
Dim SW As New StringWriter(SB)
Dim htmlTW As New HtmlTextWriter(SW)
gv.RenderControl(htmlTW)

Try
'(1) Create the MailMessage instance
Dim mm As New MailMessage()

'(2) Assign the MailMessage To and From properties
mm.To.Add("(e-mail address removed)")
mm.From = New MailAddress("(e-mail address removed)", "Ketocalc Web
Site")

'(3) Assign the MailMessage's properties
mm.Subject = "Weekly Planner attached"
mm.Body = htmlTW.ToString
mm.IsBodyHtml = True

'(4) Create the SmtpClient object
Dim smtp As New SmtpClient

'(5) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)

Catch
'Whoops, some problem sending email!
'Just send the user onto CustomErrorPage.aspx...
Dim strurl As String
strurl = "~/Errors/UnknownError.aspx?err=An Error occurred
attempting" & _
" to email the Menu Planner. The error details were sent
to the web administrator."
Server.Transfer(strurl, True)
End Try

End Sub
 
Back
Top