Emailing rows of text into an E-mail body.

G

Guest

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 table like format within an e-mail
message.

Thanks for any help,
Michael
 
W

Walter Wang [MSFT]

Hi Michael,

Short answer:

1) Create following class:

Public Class EmailReadyPage
Inherits System.Web.UI.Page

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
System.Web.UI.Control)
'DO NOTHING
End Sub
End Class

2) Inherit your WebForm from above class.

3) In server-side code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim sb As New StringBuilder
Dim sw As New IO.StringWriter(sb)
Dim writer As New HtmlTextWriter(sw)
GridView1.RenderControl(writer)

Dim mail As New Net.Mail.MailMessage

mail.From = New Net.Mail.MailAddress(...)
mail.To.Add(...)
mail.Subject = "This is the GridView's output"

mail.IsBodyHtml = True
mail.Body = sb.ToString()

Dim smtp As New Net.Mail.SmtpClient(...)
' set smtp.Credentials if necessary
smtp.Send(mail)
End Sub


Long answer:

#ASP.NET.4GuysFromRolla.com: Enhancing the 'Email the Rendered Output of an
ASP.NET Web Control' Code
http://aspnet.4guysfromrolla.com/articles/102203-1.aspx

#ASP.NET.4GuysFromRolla.com: Enhancing the 'Email the Rendered Output of an
ASP.NET Web Control' Code, Part 2
http://aspnet.4guysfromrolla.com/articles/102203-1.2.aspx


Hope this helps.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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