文本文件和aspx文件放在统一文件夹下即可。
reportfile.txt
站点名称,网站地址,创建日期
【孟宪会之精彩世界】之dhtml版本,http://lucky.myrice.com,2000-1-1
【孟宪会之精彩世界】之asp版本,http://sz.luohuedu.net/xml/,2003-12-12
【孟宪会之精彩世界】之.net版本,http://dotnet.aspx.cc/,2004-1-1
【孟子e章】专栏,http://blog.csdn.net/net_lover/,2004-1-6
【孟子e章】blog,http://ms.mblogger.cn/net_lover,2004-1-6
reportfile.aspx
<%@ page language=”c#” autoeventwireup=”true” %>
<html>
<head>
<script runat=”server”>
void page_load(object sender, eventargs e)
{
string connectionstring;
string sqlstring;
connectionstring = “provider=microsoft.jet.oledb.4.0;data source=” + server.mappath(“.”) + “;extended properties=\”text;hdr=yes;fmt=delimited\””;
sqlstring = “select * from reportfile.txt”;
system.data.oledb.oledbconnection connectiontext = new system.data.oledb.oledbconnection();
connectiontext.connectionstring = connectionstring;
connectiontext.open();
system.data.oledb.oledbdataadapter adaptertext = new system.data.oledb.oledbdataadapter(sqlstring, connectiontext);
system.data.dataset datasettext = new system.data.dataset(“textfiles”);
adaptertext.fill(datasettext, “textfile”);
datagrid1.datasource = datasettext;
datagrid1.databind();
connectiontext.close();
}
void dg_itemdatabind(object sender, datagriditemeventargs e)
{
if(e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem )
{
e.item.attributes.add(“title”,e.item.cells[0].text);
e.item.cells[0].text = “<a target=_blank href=” + e.item.cells[1].text + “>” + e.item.cells[0].text + “</a>”;
}
else
e.item.attributes.add(“style”,”background-color:#dedede”);
}
</script>
</head>
<body>
<form runat=”server”>
<asp:datagrid id=”datagrid1″ runat=”server” onitemdatabound=”dg_itemdatabind” style=”font-size:9pt”/>
</form>
</body>
</html>