Tengo el siguiente Gridview cargado desde una base de datos
Lo que necesito es enviarlo por correo pero al enviarlo aparecen solo los encabezados, ¿porque?:
Este es mi codigo:
protected void Mail_Click(object sender, EventArgs e)
{
if (SendHTMLMail())
{
Response.Write("<script>alert('Correo enviado correctamente');</script>");
}
else
{
Response.Write("<script>alert('Error al enviar correo');</script>");
}
}
public bool SendHTMLMail()
{
try
{
MailMessage Msg = new MailMessage();
MailAddress fromMail = new MailAddress("[email protected]");
// Sender e-mail address.
Msg.From = fromMail;
//Recipient e-mail address.
Msg.To.Add(new MailAddress("[email protected]"));
// Subject of e-mail
Msg.Subject = "Seguimiento a Produccion";
Msg.Body += GetGridviewData(GridView1);
Msg.IsBodyHtml = true;
string sSmtpServer = "";
sSmtpServer = "smtp.gmail.com";
SmtpClient a = new SmtpClient();
a.Host = sSmtpServer;
a.Port = 587;
a.Credentials = new System.Net.NetworkCredential("[email protected]", "pass");
a.EnableSsl = true;
a.Send(Msg);
return true;
}
catch (Exception er)
{
er.ToString();
return false;
}
}
public string GetGridviewData(GridView gv)
{
StringBuilder sb = new StringBuilder();
StringWriter textwriter = new StringWriter(sb);
HtmlTextWriter htmlwriter = new HtmlTextWriter(textwriter);
try
{
gv.RenderControl(htmlwriter);
htmlwriter.Flush();
textwriter.Flush();
htmlwriter.Dispose();
textwriter.Dispose();
}
catch (Exception er)
{
er.ToString();
}
return sb.ToString();
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time. */
}