Solved

Embed gridview content in e-mail

Posted on 2011-02-17
5
962 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
 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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