在ASP.NET 2.0中直接得到本页面生成的HTML代码
2007-07-29 11:46
579 查看
在ASP.NET 2.0中,有时候需要对ASP.NET生成的HTML代码进行处理,或者是保存成静态文件。ASP.NET 提供了直接将请求保存成文件的方法:HttpRequest.SaveAs方法。下面这个方法就是在ASP.NET 2.0中得到ASP.NET生成的HTML代码,同时,生成一个静态文件的方法。
C#
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Page Language="C#" AutoEventWireup="true" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<script runat="server">...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// 计算数据,完全可以从数据看取得
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ICollection CreateDataSource( )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Data.DataTable dt = new System.Data.DataTable();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Data.DataRow dr;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("学生班级", typeof(System.String)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("学生姓名", typeof(System.String)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("语文", typeof(System.Decimal)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("数学", typeof(System.Decimal)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("英语", typeof(System.Decimal)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("计算机", typeof(System.Decimal)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (int i = 0 ; i < 50 ; i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Random rd = new System.Random(Environment.TickCount * i); ;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr = dt.NewRow();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[0] = "班级" + i.ToString();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[1] = "【孟子E章】" + i.ToString();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[2] = System.Math.Round(rd.NextDouble() * 100, 2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[3] = System.Math.Round(rd.NextDouble() * 100, 2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[4] = System.Math.Round(rd.NextDouble() * 100, 2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[5] = System.Math.Round(rd.NextDouble() * 100, 2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Rows.Add(dr);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Data.DataView dv = new System.Data.DataView(dt);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return dv;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void Page_Load( object sender, EventArgs e )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!IsPostBack)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GridView1.DataSource = CreateDataSource();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GridView1.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected override void Render( HtmlTextWriter writer )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.IO.StringWriter html = new System.IO.StringWriter();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(html);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
base.Render(tw);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.IO.StreamWriter sw;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw = new System.IO.StreamWriter(Server.MapPath("a.htm"), false, System.Text.Encoding.Default);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw.Write(html.ToString());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
tw.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Response.Write(html.ToString());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html xmlns="http://www.w3.org/1999/xhtml">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>得到ASP.NET生成的HTML</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<form id="Form1" runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:GridView ID="GridView1" runat="server" Font-Size="12px" BackColor="#FFFFFF"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
GridLines="Both" CellPadding="4" Width="560">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<HeaderStyle BackColor="#EDEDED" Height="26px" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:GridView>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</form>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
VB.NET
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ Page Language="VB" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<script runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
Function CreateDataSource()Function CreateDataSource() As ICollection
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim dt As System.Data.DataTable = New System.Data.DataTable
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim dr As System.Data.DataRow
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("学生班级", GetType(System.String)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("学生姓名", GetType(System.String)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("语文", GetType(System.Decimal)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("数学", GetType(System.Decimal)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("英语", GetType(System.Decimal)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("计算机", GetType(System.Decimal)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim i As Integer = 0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
For i = 0 To 50 - 1
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim rd As System.Random = New System.Random(Environment.TickCount * i)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr = dt.NewRow
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(0) = "班级" + i.ToString
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(1) = "【孟子E章】" + i.ToString
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(2) = System.Math.Round(rd.NextDouble * 100, 2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(3) = System.Math.Round(rd.NextDouble * 100, 2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(4) = System.Math.Round(rd.NextDouble * 100, 2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(5) = System.Math.Round(rd.NextDouble * 100, 2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Rows.Add(dr)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Next
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim dv As System.Data.DataView = New System.Data.DataView(dt)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Return dv
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
End Function
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
Protected Sub Page_Load()Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
If Not IsPostBack Then
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GridView1.DataSource = CreateDataSource()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GridView1.DataBind()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
End If
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
End Sub
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
Protected Overloads Overrides Sub Render()Sub Render(ByVal writer As HtmlTextWriter)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim html As System.IO.StringWriter = New System.IO.StringWriter
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim tw As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(html)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
MyBase.Render(tw)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim sw As System.IO.StreamWriter
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw = New System.IO.StreamWriter(Server.MapPath("a.htm"), False, System.Text.Encoding.Default)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw.Write(html.ToString)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw.Close()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
tw.Close()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Response.Write(html.ToString)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
End sub
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html xmlns="http://www.w3.org/1999/xhtml">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>得到ASP.NET生成的HTML</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<form id="Form1" runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:GridView ID="GridView1" runat="server" Font-Size="12px" BackColor="#FFFFFF"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
GridLines="Both" CellPadding="4" Width="560">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<HeaderStyle BackColor="#EDEDED" Height="26px" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:GridView>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</form>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html
C#
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Page Language="C#" AutoEventWireup="true" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<script runat="server">...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// 计算数据,完全可以从数据看取得
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ICollection CreateDataSource( )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Data.DataTable dt = new System.Data.DataTable();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Data.DataRow dr;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("学生班级", typeof(System.String)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("学生姓名", typeof(System.String)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("语文", typeof(System.Decimal)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("数学", typeof(System.Decimal)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("英语", typeof(System.Decimal)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(new System.Data.DataColumn("计算机", typeof(System.Decimal)));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (int i = 0 ; i < 50 ; i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Random rd = new System.Random(Environment.TickCount * i); ;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr = dt.NewRow();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[0] = "班级" + i.ToString();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[1] = "【孟子E章】" + i.ToString();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[2] = System.Math.Round(rd.NextDouble() * 100, 2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[3] = System.Math.Round(rd.NextDouble() * 100, 2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[4] = System.Math.Round(rd.NextDouble() * 100, 2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr[5] = System.Math.Round(rd.NextDouble() * 100, 2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Rows.Add(dr);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Data.DataView dv = new System.Data.DataView(dt);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return dv;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void Page_Load( object sender, EventArgs e )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!IsPostBack)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GridView1.DataSource = CreateDataSource();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GridView1.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected override void Render( HtmlTextWriter writer )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.IO.StringWriter html = new System.IO.StringWriter();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(html);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
base.Render(tw);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.IO.StreamWriter sw;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw = new System.IO.StreamWriter(Server.MapPath("a.htm"), false, System.Text.Encoding.Default);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw.Write(html.ToString());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
tw.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Response.Write(html.ToString());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html xmlns="http://www.w3.org/1999/xhtml">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>得到ASP.NET生成的HTML</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<form id="Form1" runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:GridView ID="GridView1" runat="server" Font-Size="12px" BackColor="#FFFFFF"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
GridLines="Both" CellPadding="4" Width="560">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<HeaderStyle BackColor="#EDEDED" Height="26px" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:GridView>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</form>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
VB.NET
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ Page Language="VB" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<script runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
Function CreateDataSource()Function CreateDataSource() As ICollection
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim dt As System.Data.DataTable = New System.Data.DataTable
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim dr As System.Data.DataRow
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("学生班级", GetType(System.String)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("学生姓名", GetType(System.String)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("语文", GetType(System.Decimal)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("数学", GetType(System.Decimal)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("英语", GetType(System.Decimal)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Columns.Add(New System.Data.DataColumn("计算机", GetType(System.Decimal)))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim i As Integer = 0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
For i = 0 To 50 - 1
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim rd As System.Random = New System.Random(Environment.TickCount * i)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr = dt.NewRow
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(0) = "班级" + i.ToString
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(1) = "【孟子E章】" + i.ToString
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(2) = System.Math.Round(rd.NextDouble * 100, 2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(3) = System.Math.Round(rd.NextDouble * 100, 2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(4) = System.Math.Round(rd.NextDouble * 100, 2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dr(5) = System.Math.Round(rd.NextDouble * 100, 2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dt.Rows.Add(dr)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Next
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim dv As System.Data.DataView = New System.Data.DataView(dt)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Return dv
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
End Function
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
Protected Sub Page_Load()Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
If Not IsPostBack Then
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GridView1.DataSource = CreateDataSource()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
GridView1.DataBind()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
End If
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
End Sub
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
Protected Overloads Overrides Sub Render()Sub Render(ByVal writer As HtmlTextWriter)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim html As System.IO.StringWriter = New System.IO.StringWriter
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim tw As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(html)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
MyBase.Render(tw)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Dim sw As System.IO.StreamWriter
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw = New System.IO.StreamWriter(Server.MapPath("a.htm"), False, System.Text.Encoding.Default)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw.Write(html.ToString)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sw.Close()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
tw.Close()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Response.Write(html.ToString)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
End sub
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html xmlns="http://www.w3.org/1999/xhtml">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>得到ASP.NET生成的HTML</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<form id="Form1" runat="server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:GridView ID="GridView1" runat="server" Font-Size="12px" BackColor="#FFFFFF"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
GridLines="Both" CellPadding="4" Width="560">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<HeaderStyle BackColor="#EDEDED" Height="26px" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:GridView>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</form>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
相关文章推荐
- [导入]在ASP.NET 2.0中直接得到本页面生成的HTML代码
- ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码 (转)
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码
- 在ASP.NET 2.0中直接得到本页面生成的HTML代码