Click here to Skip to main content
15,884,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
I have gridview having the table name tblemployee coulmn name empid ,  fisrtname , lastname , Email
now i want to send the gridview as attachment to all the email id that exist in the tblemployee how can i do so
Posted

1 solution

You can convert the Gridview to html or excel then send this file via email.

For e.g.
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;
    //Send email
}
 
Share this answer
 
Comments
Orcun Iyigun 30-May-13 6:33am    
He will also need to add the following code as well:
public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. */
}

Otherwise he will have an exception pn the gv.RenderControl(hw); line.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900