vb.net <%@ page language="vb" %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www./tr/xhtml1/dtd/xhtml1-transitional.dtd"> <script runat="server"> function createdatasource() as icollection dim dt as system.data.datatable = new system.data.datatable dim dr as system.data.datarow dt.columns.add(new system.data.datacolumn("學(xué)生班級(jí)", gettype(system.string))) dt.columns.add(new system.data.datacolumn("學(xué)生姓名", gettype(system.string))) dt.columns.add(new system.data.datacolumn("語(yǔ)文", gettype(system.decimal))) dt.columns.add(new system.data.datacolumn("數(shù)學(xué)", gettype(system.decimal))) dt.columns.add(new system.data.datacolumn("英語(yǔ)", gettype(system.decimal))) dt.columns.add(new system.data.datacolumn("計(jì)算機(jī)", gettype(system.decimal))) dim i as integer = 0 for i = 0 to 50 - 1 dim rd as system.random = new system.random(environment.tickcount * i) dr = dt.newrow dr(0) = "班級(jí)" + i.tostring dr(1) = "【孟子e章】" + i.tostring dr(2) = system.math.round(rd.nextdouble * 100, 2) dr(3) = system.math.round(rd.nextdouble * 100, 2) dr(4) = system.math.round(rd.nextdouble * 100, 2) dr(5) = system.math.round(rd.nextdouble * 100, 2) dt.rows.add(dr) next dim dv as system.data.dataview = new system.data.dataview(dt) return dv end function protected sub page_load(byval sender as object, byval e as eventargs) if not ispostback then gridview1.datasource = createdatasource() gridview1.databind() end if end sub protected overloads overrides sub render(byval writer as htmltextwriter) dim html as system.io.stringwriter = new system.io.stringwriter dim tw as system.web.ui.htmltextwriter = new system.web.ui.htmltextwriter(html) mybase.render(tw) dim sw as system.io.streamwriter sw = new system.io.streamwriter(server.mappath("a.htm"), false, system.text.encoding.default) sw.write(html.tostring) sw.close() tw.close() response.write(html.tostring) end sub </script> <html xmlns="http://www./1ArrayArrayArray/xhtml"> <head> <title>得到asp.net生成的html</title> </head> <body> <form id="form1" runat="server"> <asp:gridview id="gridview1" runat="server" font-size="12px" backcolor="#ffffff" gridlines="both" cellpadding="4" width="560"> <headerstyle backcolor="#ededed" height="26px" /> </asp:gridview> </form> </body> </html |
|