PDA

View Full Version : Emailing info displayed in a detailsview or gridview


xbabigyrlx
06-28-2006, 09:58 PM
I have a web page that fills a detailsview (DetailsView1) and a gridview(GridView1) with info from a database. I need to be able to send an email to customers that contains this information.

I have the email set up and working I just need to know how to include this information in the body.

Is it possible to pull it from the page it is already displayed on or do I need to pull it from the database again? If so, how do I do this?



Thanks for your help and your time,

otaku149
06-29-2006, 01:34 AM
Hello xbabigyrlx,


Dim sb As New StringBuilder()
Dim sw As New StringWriter(sb)
Dim htw As New HtmlTextWriter(sw)
GridView1.RenderControl(htw)
Dim MyGridViewHTML As String = sb.ToString()

Dim msg As New MailMessage
'some code...
msg.IsBodyHtml = True
msg.Body = MyGridViewHTML
'some code...


Also add this to your page:

Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
'keep this empty
End Sub

xbabigyrlx
06-29-2006, 02:18 AM
Sounds great I will try it.... Thanks so much for your time... :thumbsup:

xbabigyrlx
06-29-2006, 02:54 PM
I am using c# how do I change the code to make it work?


thanks!

otaku149
06-29-2006, 03:42 PM
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
string MyGridViewHTML = sb.ToString();



public override void VerifyRenderingInServerForm(Control control)
{
//keep this empty
}

xbabigyrlx
06-29-2006, 05:03 PM
This works great for my grid that doesn't have any sort commands.... is there an easy fix for the ones that do. Those give me an error message.....


Exception Details: System.InvalidOperationException: RegisterForEventValidation can only be called during Render();


thanks

xbabigyrlx
06-29-2006, 05:53 PM
Ok I got it to work with the sorting... my new problem is I have 2 gridviews and 1 details view.... the 2 gridviews work fine but I get an error message when I try to do the detailsview.... any suggestions....


Thanks

otaku149
06-29-2006, 06:22 PM
I get an error message when I try to do the detailsview

What error message exactly?

xbabigyrlx
06-29-2006, 06:43 PM
This is the error message I am getting:

System.InvalidOperationException: RegisterForEventValidation can only be called during Render();

This was the same error message I was getting on one of my gridviews until I changed the sort to false (it really wasn't needed anyways :) )

Since my detailsview doesn't sort I'm not sure why I am getting this error.....

Thanks for your help...

otaku149
06-29-2006, 07:21 PM
That's strange because I used that on many of my apps and it's work fine for me, did you add the following code?

public override void VerifyRenderingInServerForm(Control control)
{
//keep this empty
}

Also try to set EnableEventValidation to false in your page directive:

<%@ Page Language="C#" EnableEventValidation="false" %>

But before using it, read the following to understand the EnableEventValidation property:
http://msdn2.microsoft.com/en-us/library/system.web.ui.page.enableeventvalidation.aspx

xbabigyrlx
06-29-2006, 08:02 PM
Ok I added

<%@ Page Language="C#" EnableEventValidation="false" %>

and it works fine now.... Thanks for all of your time and help! :thumbsup: