欢迎光临
我们一直在努力

绑定txt文件到DataGrid-.NET教程,数据库应用

建站超值云服务器,限时71元/月

文本文件和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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 绑定txt文件到DataGrid-.NET教程,数据库应用
分享到: 更多 (0)