Email GridView Control

2019/7/24 4:11:28 人评论 次浏览 分类:学习教程

原文链接:http://www.cnblogs.com/MYBLOG-2007/archive/2007/03/16/677407.html

Some days ago, a customer asked me about how to email a gridView Control. After some effort, I have solved the problem. First render the GridView to html and then set the html as the email message body.
But how can we render the GridView to html? The following code provide an anwser.

public partial class GridView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public string RenderControlToHtml(Control c)
    {
        System.IO.StringWriter sw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
        c.RenderControl(hw);
        return sw.ToString();
    }
    protected override void Render(HtmlTextWriter writer)
    {
        TextBox1.Text = RenderControlToHtml(GridView1);
        base.Render(writer);
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
       
    }
}
here I want to mention the VerifyRenderingInServerForm method, we must override the method inorder to avoid the error message telling you that the server control must be put in the <form runat="server"> tag.

转载于:https://www.cnblogs.com/MYBLOG-2007/archive/2007/03/16/677407.html

相关资讯

    暂无相关的资讯...

共有访客发表了评论 网友评论

验证码: 看不清楚?
    -->