Ankit Agarwal

Ankit Agarwal

  • NA
  • 379
  • 253k

How to send gridview in email body using c# asp.net?

Feb 6 2014 1:18 AM
Hello, 
How to send gridview in email body using c# asp.net?

I am using this code for send gridview in email body, but i have a problem for this,
One image also in my gridview, my gridview sending but image it's not sending and grid formatting also it's not sending, only simple grid sending and delete button also sending.

protected void SendEmail(object sender, EventArgs e)
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
GridView1.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
MailMessage mm = new MailMessage("[email protected]", "[email protected]");
mm.Subject = "GridView Email";
mm.Body = "GridView: <hr />" + sw.ToString(); ;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "[email protected]";
NetworkCred.Password = "";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
}
}

My gridview it's not sending in proper format with image.
How can we send my Gridview in proper format?
Please help me.

Thanks in Advance
Ankit Agarwal
Website Developer

Answers (1)