获得服务器控件生成的HTML的方法
下面以DataSet为例子,代码摘自jasmineou的ajax在.net中与server控件的交互
DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables["db"];
dg.DataBind();
//实例化一个HtmlTextWriter的类
System.Text.StringBuilder strb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter( strb );
System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter( sw );
//执行控件的render并输出到HtmlTextWriter里
dg.RenderControl( htw );
string s = strb.ToString();
dg.DataSource = ds.Tables["db"];
dg.DataBind();
//实例化一个HtmlTextWriter的类
System.Text.StringBuilder strb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter( strb );
System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter( sw );
//执行控件的render并输出到HtmlTextWriter里
dg.RenderControl( htw );
string s = strb.ToString();