当前位置: 首页 > 图文教程 > 网络编程 > ASP > 绑定txt文件到DataGrid

ASP
深入研究“用ASP上载文件”(一)
深入研究“用ASP上载文件”(二)
一个投票系统的源程序(coveryourasp.com)
一 些 ASP 小 源 程 序
用ASP制作个性化的调查板(附源程序)
一些源程序 - 获得文件大小和字符串处理
用ASP创建日志文件(附源程序)
在一个ASP页面停留的多少时间的程序
用VB6做一个简单的文件上传组件(一)
用VB6做一个简单的文件上传组件(二)
构建你的网站新闻自动发布系统之七
实 现 滚 动 新 闻
网上“店铺”DIY(1)
网上“店铺”DIY(2)
网上“店铺”DIY(3)
负载平衡环境下的ASP会话管理(1)
负载平衡环境下的ASP会话管理(2)
FrontPage创建HTML/ASP混合页面Ⅰ
FrontPage创建HTML/ASP混合页面Ⅱ
在ASP应用中验证用户身份(1)

ASP 中的 绑定txt文件到DataGrid


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 35 ::
收藏到网摘: n/a

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