·您的位置: 首页 » 资源教程 » 编程开发 » ASP » 绑定TXT文件到DATAGRID

绑定TXT文件到DATAGRID

类别: ASP教程  评论数:0 总得分:0
ReportFile.txt

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>
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1