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

Reading number is top 10 articles
用C#和ADO.NET建立一个数据绑定网格_[Asp.Net教程]
SQL 2000和Sql 2005相互转换方法_[SQL Server教程]
C#教程: 控制鼠标操作使用实例
独家:C#数据库操作的三种经典用法_.net资料_编程技术
怎么样学习PHP_[PHP教程]
PHP截取UTF-8字符串,解决半字符问题_[PHP教程]
C#设计的一个向导程序(Wizard)框架_[Asp.Net教程]
datagrid导出excel文件给客户端下载的3种方法_[Asp.Net教程]
asp.net中对数据库表插入null空值的问题_.net资料_编程技术
ASP.NET Remoting体系结构(四)
Reading number is top 10 pictures
From China fortress sora aoi2
Embarrassing things comic collection2
一万二一支的万珂,用得真心肉疼。
清纯性感的美眉1
The real super beauty10
The hot big eye big breast beauty1
2012 national geographic daily picture2
六种更聪明的工作方法
西游日记3
什么叫国家
Download software ranking
VC++6.0简体中文版
C++编程教程第三版
The Bermuda triangle2
Tram sex maniac 2 (H) rar bag15
Tram sex maniac 2 (H) rar bag13
变速齿轮3.26
Love the forty days
SP3 for SQL2000
Ashlynn Video3
Boxer's Top ten classic battle7
qq published in(发表于) 2014/7/9 1:39:24 Edit(编辑)
asp.net中DataList属性、方法和事件

asp.net中DataList属性、方法和事件

asp.net中DataList属性、方法和事件

DataList属性、方法和事件

1.DataList属性

DataList控件常用属性及说明如表1所示。

下面对比较重要的属性进行详细介绍。

(1)DataKeyField属性。用于获取或设置由DataSource属性指定数据源中的键的字段。

语法:

[ThemeableAttribute(False)]

public virtual string DataKeyField { get; set; }

属性值:由DataSource属性指定的数据源中的键字段的名称。

(2)DataSource属性。用于获取或设置DataList控件所显示数据的数据源。

语法:

[ThemeableAttribute(False)]

[BindableAttribute(True)]

public virtual Object DataSource { get; set; }

属性值:用于为DataList控件提供数据值的集合。

(3)DataKeys属性。用于获取DataKeyCollection对象,在DataKeyCollection对象中存储数据列表控件中每个记录的键值。

语法:

public DataKeyCollection DataKeys { get; }

属性值:返回DataKeyCollection对象。

(4)Items属性。用于获取数据控件内单独项的DataListItem对象的集合。

语法:

public virtual DataListItemCollection Items { get; }

属性值:返回DataList控件内单独项的DataListItem对象的集合。

示例

DataKeyField、DataSource、DataKeys和Items属性的使用

本示例主要用来显示和删除商品信息,示例运行结果如图1所示,当单击“1号商品”的【删除】按扭后,运行结果如图2所示。



图1 显示商品信息



图2 显示删除后的商品信息

程序代码如下。

在绑定商品数据信息时,通过指定DataList控件的DataSource属性值,获取商品信息,并通过DataKeyField属性指定该商品信息中的键字段的名称。其代码如下:

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

myConn.Open();

string sqlStr = "select * from tb_GoodsInfo";

SqlDataAdapter da = new SqlDataAdapter(sqlStr, myConn);

DataSet ds = new DataSet();

da.Fill(ds, "Goods");

DataList1.DataSource = ds.Tables["Goods"].DefaultView;

DataList1.DataKeyField = "GoodsID";

DataList1.DataBind();

myConn.Close();

完整程序代码如下:

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

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







无标题页
















BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" GridLines="Both" OnItemCommand="DataList1_ItemCommand" >











  商品的详细信息









商品编号


<%#Eval("GoodsID")%>






商品名称


<%#Eval("GoodsName") %>






商品价格


<%#Eval("GoodsPrice") %>



添加到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.