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

ASP
开辟一条自由ASP快车道
用XML结合数据库,给服务器减负。
纯编码实现数据库的建立或压缩
多个表单和多个图片一起上传完美解决方案
列表项可上下移动的Multiple列表
模拟QQ的下拉列表选择图象
利用FSO取得BMP,JPG,PNG,GIF文件信息(大小,宽、高等)
二级域名原理以及程序,申请即可开通.
利用ASP+XML架设在线考试系统
ASP项目中的通用条件查询模块
一个为字符串中的网址加上链接的程序例子
用Agent+ASP技术制作语音聊天室
多表单域无组件文件上传的例子
使用xmlhttp为网站增加股市行情查询功能
用ASP开发WEB日期选择器
javascript+HTML仿造VB里的MonthView控件
使用xmlHttp结合ASP,实现网页的异步调用
调用DirectX的组件实现的时钟
在ASP页里面注册DLL的VBScript CLASS
ASP程序界面的多语言支持

ASP 中的 绑定txt文件到DataGrid


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 79 ::
收藏到网摘: 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>