Hello I am working in asp.net and in that i am using grid view and now i want to convert grid view data which is dynamic to the html table so i can send an email. if any one know it please tell me. Thank You
+2
A:
You can use
using System.IO;
using System.Text;
using System.Net.Mail;
private string GridViewToHtml(GridView gv)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);
gv.RenderControl(hw);
return sb.ToString();
}
protected void SendMailButton_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
mail.Body = GridViewToHtml(GridView1);
mail.IsBodyHtml = true;
// The same logic as you use for sending mail
}
public override void VerifyRenderingInServerForm(Control control)
{
}
Pandiya Chendur
2010-07-09 06:18:51
my problem is npt sending email, my problem is that how to convert asp.net grid view data in to tables
Renu123
2010-07-09 09:48:45
@Renu123c why you need tables?
Pandiya Chendur
2010-07-09 09:56:10
@Renu123 - You will get gridview html in `sb.ToString();`. I think this is the answer.
Krunal
2010-07-09 11:52:15