473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1397
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stanley Cheung | last post by:
Hi all, I am developing the application for send emailing list, actually, i can perform to send a email 1 by 1 and do it on aspx page. I have a enquiry that how can the application change to...
3
by: tafs7 | last post by:
My code below is supposed to email me when an error occurs on the application, but it's not emailing anything. Am I missing something? I know the smtp servers I've tried work. I even added a...
4
by: Mike Moore | last post by:
What is the best way to launch outlook from an asp.net web page? Can you do this using MAPI or is there a control that you can purchase? We are unable to use SMTP. We use MS Exhange and MAPI...
6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
2
by: Tim Hunter | last post by:
I have two questions regarding emailing from Access. My first question relates to how many email addresses is too much. I have a client who wants to email 1500 people at once. Is this possible or...
2
by: =?Utf-8?B?TWljaGFlbCBkZSBWZXJh?= | last post by:
To all, I was wondering if someone has sample VB.NET code that will help me send rows of a gridview into a body section of an e-mail. My goal is to present multiple rows within a gridview to a...
20
by: paul814 | last post by:
I've been working on this for some time now and have gotten nowhere...hoping someone here can help. I want to take and email all records in a database for the current date when this php page is...
0
by: Ty | last post by:
I have a page that has three gridviews on it. In each gridview the first column is a link button representing a Database ID field. What I'm trying to accomplish is to email that page and click on...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.