Embed gridview content in e-mail

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

danielivanov2Asked:
Who is Participating?
 
Obadiah ChristopherConnect With a Mentor Commented:
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
 
Kalpesh ChhatralaSoftware ConsultantCommented:
0
 
danielivanov2Author Commented:
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
 
danielivanov2Author Commented:
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
 
Obadiah ChristopherCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.