Emailing a GridView


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
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top