468,115 Members | 2,036 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,115 developers. It's quick & easy.

Emailing a GridView

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("da***@myweb.com")
mm.From = New MailAddress("da***@myweb.com", "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
Nov 20 '08 #1
1 1323
First, put

Option Explicit ON
Option Strict ON

at the top of your vb code.
Second, look at the documentation

http://msdn.microsoft.com/en-us/libr...r_methods.aspx
the ToString() method is just going to tell you what the object is (since
its inherited from Object).

So what you're getting in the msgBody is expected.

ToString is not the magic cure-all for getting "stuff".

"David C" <dl*****@lifetimeinc.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>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("da***@myweb.com")
mm.From = New MailAddress("da***@myweb.com", "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

Nov 20 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stanley Cheung | last post: by
4 posts views Thread by Mike Moore | last post: by
6 posts views Thread by Nalaka | last post: by
2 posts views Thread by Tim Hunter | last post: by
2 posts views Thread by =?Utf-8?B?TWljaGFlbCBkZSBWZXJh?= | last post: by
20 posts views Thread by paul814 | last post: by
3 posts views Thread by Peter | last post: by
3 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.