All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
delphi一个简单组件编程示例
delphi程序中动态创建、删除视图
菜鸟的最爱,.NET经典代码汇总(五)_.net资料_编程技术
SQL循序渐进(10)合计函数_[SQL,Server教程]
用ASP.NET2.0在数据库中存储二进制文件_[Asp.Net教程]
菜鸟学习:动态网页PHP基础学习笔记_php资料_编程技术
Asp.net页面输出成HTML页面_[Asp.Net教程]
PHP技巧:PHP文件系统基本操作类_[PHP教程]
PHP的session的疑难问题及解决方法_[PHP教程]
Asp.net2.0实现多语言网页的方法_[Asp.Net教程]
Reading number is top 10 pictures
In the world the most mysterious 21 place landscape2
2012 national geographic daily picture4
人美胸美腿更美1
29 the belle stars after bath figure4
XuRe xuan cool and refreshing photoes2
牛奶和人奶哪个好?
到南昌西站了2
30 beautiful school beauty6
Original author said, this is the Hengyang people
A resort photographed beautiful young woman change clothes process vomiting blood2
Download software ranking
致我们终将逝去的青春
Eclipse 4.2.2 For Win32
传奇私服架设教程
星际争霸1.08硬盘免安装版
Proficient in Eclipse
WebService在.NET中的实战应用教学视频 → 第3集
少妇苏霞全本
Detective task-the top secret prostitution files
The Bermuda triangle2
Unix video tutorial8
qq published in(发表于) 2014/7/9 1:37:20 Edit(编辑)
asp.net2.0控件DataList实例应用

asp.net2.0控件DataList实例应用

asp.net2.0控件DataList实例应用

DataList控件实例应用

在网站开发中,经常需要使用DataList控件显示具有主次结构的数据。本实例中,通过在DataList控件中嵌套一个DataList控件来根据员工姓名显示员工的详细信息。实例运行结果如图1所示。



图1 使用DataList控件显示具有主次结构的数据

程序开发步骤如下所示。

(1)新建一个网站,将其命名为Ex22_02,默认主页名为Default.aspx。

(2)Default.aspx页面涉及的控件如表2所示。



表2 Default.aspx页面用到的控件

(3)主要程序代码如下。

在HTML源设计视图中对嵌套的DataList控件进行数据绑定,将其DataSource属性设置为建立的表间关系,同时将其DataKeyField属性设置为建立表间关系时所依据的数据表字段,实现代码如下:





在Default.aspx页的Page_Load事件中,首先从数据表中检索数据,同时取得要显示的主数据和从数据,填充到DataSet中,然后根据用户姓名创建DataRelation对象,并通过使用数据绑定方法将相关信息绑定到DataList控件中。Default.aspx页Page_Load事件代码如下网站源代码

protected void Page_Load(object sender, EventArgs e)

{//本教程来自:http://www.isstudy.com

SqlConnection myConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());

string sqlStr = "select top 3* from tb_EmpID select top 3a.*,b.UserID from tb_Employee as a inner join tb_EmpID as b on a.UserID=b.UserID";

SqlDataAdapter myda = new SqlDataAdapter(sqlStr, myConn);

DataSet myds = new DataSet();

myConn.Open();

myda.Fill(myds);

myds.Tables[0].TableName = "tb_EmpID";

myds.Tables[1].TableName = "tb_Employee";

DataColumn Parent = myds.Tables["tb_EmpID"].Columns["UserLoginName"];

DataColumn Child = myds.Tables["tb_Employee"].Columns["UserLoginName"];

DataRelation tableRelation = new DataRelation("tableRelation", Parent, Child, False);

myds.Relations.Add(tableRelation);

DataList1.DataSource = myds.Tables["tb_EmpID"].DefaultView;

DataList1.DataBind();

myConn.Close();

}

完整程序代码如下:

★ ★★★★Default.aspx页面设计文件完整程序代码★★★★★

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>







DataList实现主细表















员工详细信息






















员工姓名:<%# DataBinder.Eval(Container.DataItem, "UserLoginName")%>














添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.