Grid in email

T

tshad

Is there a way to easily put a Datagrid in an email?

I want to send a select result in the form of a Datagrid via an email to
some of our clients.

Thanks,

Tom
 
C

Carlos Albert

About a month ago I had the same situation and didn't find a way to do it,
at least an easy way. I ended creating an .html with <table>'s, reading that
HTML and asigning values to it. Then sending it through email.body

I can send you the code if you want it.
 
S

Siva M

Create the HTML markup for the table and use it as the body for the email.
The email should have the body content type as HTML

Is there a way to easily put a Datagrid in an email?

I want to send a select result in the form of a Datagrid via an email to
some of our clients.

Thanks,

Tom
 
T

tshad

So it has to be done by hand then.

I was hoping there was someway to use a Datagrid or datalist to create the
table and put the table into the body of the message.

Thanks,

Tom
 
S

Siva M

Well, there is way to do it:

System.Text.StringBuilder sb = new System.Text.StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
DataGrid.RenderControl(htw);
// Now, sb.ToString() will get you the HTML for the DataGrid.

So it has to be done by hand then.

I was hoping there was someway to use a Datagrid or datalist to create the
table and put the table into the body of the message.

Thanks,

Tom
 
T

tshad

Siva M said:
Well, there is way to do it:

System.Text.StringBuilder sb = new System.Text.StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
DataGrid.RenderControl(htw);

That sounds interesting.

Would I do this in my Page_load or PostBack after Binding the DataGrid?

I assume it would be something like:

dbReader = myDbObject.RunProcedure("GetEmployerFavorites", parameters)
<--Gets my data
SubmissionsGrid.DataSource = dbReader
SubmissionsGrid.DataBind()
<-- Bind the data to the datagrid

System.Text.StringBuilder sb = new System.Text.StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
DataGrid.RenderControl(htw);

I can now take SB and combine it with my email and send it to someone ?

Thanks,

Tom
 

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

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top