如何在HTML表格中传输asp.net网格视图数据

Ren*_*123 4 html asp.net email gridview

我在asp.net工作,我正在使用网格视图,现在我想将网格视图数据转换为动态的html表格,以便我可以发送电子邮件.如果有人知道,请告诉我.谢谢

ACP*_*ACP 6

您可以使用

   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)
{

}
Run Code Online (Sandbox Code Playgroud)