0

要求:查询数据库并构建数据网格和图表并通过电子邮件发送此报告/信息的自动化过程。

问题:我可以使用嵌入式图像(图表)或数据网格构建报告,而不是一起构建。如何在电子邮件中同时获取图表和数据网格?

代码:

            MailMessage m = new MailMessage();
            SmtpClient smtp = new SmtpClient("smtpservername", 25);
            m.From = new System.Net.Mail.MailAddress("vananthraman@abcd.com");
            m.To.Add("vananthraman@abcd.com");
            m.Subject = "This is a test";

            AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", null, "text/plain");

            AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<img src=cid:companylogo>", null, "text/html");



            System.Net.Mail.LinkedResource logo = new System.Net.Mail.LinkedResource(path);
            logo.ContentId = "companylogo";

            htmlView.LinkedResources.Add(logo);

            m.AlternateViews.Add(plainView);
            m.AlternateViews.Add(htmlView);



            //some_query is defined here
                    using (SqlCommand cmd = new SqlCommand(some_query, connection))
                    {


                        GridView gvwBmonitor = new GridView();
                        SqlDataReader reader = cmd.ExecuteReader();
                        gvwBmonitor.DataSource = reader;
                        gvwBmonitor.DataBind();


                        m.IsBodyHtml = true;
                        StringBuilder sb = new StringBuilder();
                        HtmlTextWriter hw = new HtmlTextWriter(new StringWriter(sb));
                        gvwBookingmonitor.RenderControl(hw);

                        m.Body = m.Body + sb.ToString();
                        AlternateView htmlView2 = AlternateView.CreateAlternateViewFromString(sb.ToString(), null, "text/html");
                        m.AlternateViews.Add(htmlView2);
                        smtp.Send(m);

                    }

我只看到图表而不是网格。我怎样才能解决这个问题?

4

1 回答 1

0

您正在用图表覆盖网格。创建linkedResources的列表以及其中的每一个到alternativeView.LinkedResources

于 2013-08-28T06:46:06.743 回答