Solved

Embed gridview content in e-mail

Posted on 2011-02-17
5
960 Views
Last Modified: 2012-08-13
I'm having difficulties in embedding gridview content in email notification, RenderControl() doesn;t work. The current output is: "New Offer: System.Web.UI.HtmlTextWriter"
My code attached. Does it matter that my gridview is inside a hidden div?
Thanks
<div id="divShowDetails" style="display:none">
            <b>Detalii oferta:</b>
            <asp:GridView 
                ID="csOfferMV" AllowPaging="false" runat="server" 
                AutoGenerateColumns="false">                                                        
                <HeaderStyle CssClass="HeaderStyle" />    
                <RowStyle CssClass="RowStyle" />                  
                <AlternatingRowStyle CssClass="AlternateRowStyle" /> 
                <SelectedRowStyle CssClass="SelectedRowStyle" />
-------------------------------------------------
System.Net.Mail.MailMessage ms = new System.Net.Mail.MailMessage();
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                ms.To.Add(new System.Net.Mail.MailAddress(userEmail));
                ms.CC.Add(new System.Net.Mail.MailAddress(managerEmail));
csOfferMV.DataSource = (DataTable)Session["CustomOfferMV"];
                csOfferMV.DataBind();
                StringWriter sw = new StringWriter(sb);
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                csOfferMV.RenderControl(hw);
sb.Append(@"Customer Id: <b>" + lblCustomerId.Text + "</b>; Caz Id: <b>" + Session["CurrentCase"].ToString() + "</b>,<br/>");
sb.Append(@"<b>New Offer: " + hw + "</b><br/>");

Open in new window

0
Comment
Question by:danielivanov2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 34923352
0
 

Author Comment

by:danielivanov2
ID: 34923376
that explains how to render to excel and thereafter attach it to email - cannot it be done without creating an attachment? the point is that I need also to keep the gridview formatting
0
 
LVL 20

Accepted Solution

by:
informaniac earned 300 total points
ID: 34923527
R u able 2 c d gridviw whn u do a view source. If not I dnt think RenderControl would give u d gridview contents.
0
 

Author Closing Comment

by:danielivanov2
ID: 34923552
That's it! I was using a wrong session variable. Thanks!

PS: pls try not to use so many shortcuts when typing, its hard to understand your text. Best regards
0
 
LVL 20

Expert Comment

by:informaniac
ID: 34929318
As you see I posted it from EE Mobile. My mobile only supports WAP and I have a restriction of 120 characters per post. So can't help it. :(
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question