将控件转换成Html的形式
string ControlHTML(Control control)
{
string sHTML = string.Empty;
System.IO.StringWriter oTextWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHTMLWriter = new HtmlTextWriter(oTextWriter);
control.RenderControl(oHTMLWriter);
sHTML = oTextWriter.ToString();
return sHTML;
}
{
string sHTML = string.Empty;
System.IO.StringWriter oTextWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHTMLWriter = new HtmlTextWriter(oTextWriter);
control.RenderControl(oHTMLWriter);
sHTML = oTextWriter.ToString();
return sHTML;
}
如需将此Html在页面的指定地方输出,需要指定地方增加Literal控件,并将转换后的Html值赋给Literal控件。如下代码:
Literal1.Text = sHTML;
参考:http://www.cnblogs.com/126163/archive/2008/07/23/1249957.html