动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   Asp → 阅读文章

 绑定txt文件到DataGrid

作者:郁郁小蝎 来源:中国站长学院 
阅读 2125 人次 , 2006-2-15 14:16:00 

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

  
 本文Tagstag  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:ASP如何获取真实IP地址
· 下一篇:在用户离开页面时提示信息
· JScript 方法 - floor 方法
· 使用ASP建立Http组件
· ASP用JMail、CDO发送邮件
· 用Visual C#调用Windows API函数
· ASP漏洞集-MS IIS server/Frontpage Ext Server


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077