c#

位置:IT落伍者 >> c# >> 浏览文章

.NET 2.0中直接得到页面HTML代码


发布日期:2019年02月18日
 
.NET 2.0中直接得到页面HTML代码

在ASPNET有时候需要对ASPNET生成的HTML代码进行处理或者是保存成静态文件ASPNET 提供了直接将请求保存成文件的方法HttpRequestSaveAs方法下面这个方法就是在ASPNET 中得到ASPNET生成的HTML代码同时生成一个静态文件的方法

VBNET

<%@ Page Language=VB %>

<!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN

transitionaldtd

<script runat=server

Function CreateDataSource() As ICollection

Dim dt As SystemDataDataTable = New SystemDataDataTable

Dim dr As SystemDataDataRow

dtColumnsAdd(New SystemDataDataColumn(学生班级 GetType(SystemString)))

dtColumnsAdd(New SystemDataDataColumn(学生姓名 GetType(SystemString)))

dtColumnsAdd(New SystemDataDataColumn(语文 GetType(SystemDecimal)))

dtColumnsAdd(New SystemDataDataColumn(数学 GetType(SystemDecimal)))

dtColumnsAdd(New SystemDataDataColumn(英语 GetType(SystemDecimal)))

dtColumnsAdd(New SystemDataDataColumn(计算机 GetType(SystemDecimal)))

Dim i As Integer =

For i = To

Dim rd As SystemRandom = New SystemRandom(EnvironmentTickCount * i)

dr = dtNewRow

dr() = 班级 + iToString

dr() = 【孟子E章】 + iToString

dr() = SystemMathRound(rdNextDouble * )

dr() = SystemMathRound(rdNextDouble * )

dr() = SystemMathRound(rdNextDouble * )

dr() = SystemMathRound(rdNextDouble * )

dtRowsAdd(dr)

Next

Dim dv As SystemDataDataView = New SystemDataDataView(dt)

Return dv

End Function

Protected Sub Page_Load(ByVal sender As Object ByVal e As EventArgs)

If Not IsPostBack Then

GridViewDataSource = CreateDataSource()

GridViewDataBind()

End If

End Sub

Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)

Dim html As SystemIOStringWriter = New SystemIOStringWriter

Dim tw As SystemWebUIHtmlTextWriter = New SystemWebUIHtmlTextWriter(html)

MyBaseRender(tw)

Dim sw As SystemIOStreamWriter

sw = New SystemIOStreamWriter(ServerMapPath() False SystemTextEncodingDefault)

swWrite(htmlToString)

swClose()

twClose()

ResponseWrite(htmlToString)

End sub

</script>

<html xmlns=

<head>

<title>得到ASPNET生成的HTML</title>

</head>

<body>

<form id=Form runat=server

<asp:GridView ID=GridView runat=server FontSize=px BackColor=#FFFFFF

GridLines=Both CellPadding= Width=

<HeaderStyle BackColor=#EDEDED Height=px />

</asp:GridView>

</form>

</body>

</html>

上一篇:接口在ADO.NET中的应用

下一篇:用.NET框架实现序列化