Solved

Embed gridview content in e-mail

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now