?
Solved

Embed gridview content in e-mail

Posted on 2011-02-17
5
Medium Priority
?
965 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 1200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 20 hours left to enroll

777 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