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

Reading number is top 10 articles
让Asp.NET,DataGrid可排序,选择,分页_[Asp.Net教程]
[delphi语法2]Object Pascal语言注释语句
SQL Server2005数字转中文大写字母_[SQL Server教程]
Ajax实例教程-----级联菜单_[AJAX教程]
SqlServer存储过程函数加解密
在asp.net2.0页面部分缓存中实现缓存后替换文字内
巧用Ajax和RSS做个人门户网站_[AJAX教程]
Linux,下用PHP4连接,Oracle8i,的方法_php资料_编程技术
解决网爬工具爬取页面信息出现乱码的问题_[Asp.Net教程]
技巧:ASP.NET技术获取IP与MAC地址的方法_.net资料_编程技术
Reading number is top 10 pictures
中国的阶级现状
囚犯暴乱了咋办?
The real super beauty2
10 powerless things in life
Exquisite decoration is not paying too much2
The girl of like self-time
The money of more than 100 countries and regions22
农夫山泉变身记
On the verge of extinction of the beach1
赵惟依写真2
Download software ranking
Boxer's Top ten classic battle8
Boxer Classic video3
双旗镇刀客B
Rio big adventure
Twenty piece of palm leaf
VC++6.0培训教程
Popkart Cracked versions Mobile phone games
Tram sex maniac 2 (H) rar bag14
功夫熊猫2(下集)
虚拟机5.5.3版



















































































































C# Code
public partial class CompositeListView : System.Web.UI.Page
{
DataClassesDataContext db;
protected void Page_Load(object sender, EventArgs e)
{
if (db == null)
db = new DataClassesDataContext();
this.BindList();
}


private void BindList()
{
this.ListView1.DataSource = db.Categories;
this.ListView1.DataBind();
}


protected void ListView1_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
this.ListView1.SelectedIndex = e.NewSelectedIndex;
this.BindList();
ListView listView = this.ListView1.Items[e.NewSelectedIndex].FindControl("ListViewCompositie") as ListView;
Label label = this.ListView1.Items[e.NewSelectedIndex].FindControl("CategoryID") as Label;
var a = db.Products.Where(product => product.CategoryID == Convert.ToInt32(label.Text));
listView.DataSource = a;
listView.DataBind();
}
protected void ListView1_Sorting(object sender, ListViewSortEventArgs e)
{


}
}



另外有几个问题请教各位大虾。


1、为何我对ListView控件进行自定义时只能使用LinkButton。


2、如何将被嵌套的ListView也就是ListViewCompositie漂浮在被嵌套行的下方从而遮挡下面的列。而不是向我例子中直接将行撑开呢?(本人CSS比较菜,还望指点)


谢谢指教。





归海一刀 published in(发表于) 2014/1/30 1:13:24 Edit(编辑)
第六篇:ListView控件与DataPager控件详解(2)_[Asp.Net教程]

第六篇:ListView控件与DataPager控件详解(2)_[Asp.Net教程]

第六篇:ListView控件与DataPager控件详解(2)_[Asp.Net教程]


话接前文,今天的主要内容是如何实现嵌套数据,也就是父子表的格式。然后就是ListView的删除、插入、更新、排序。



ListView的操作


我们可以创建模板来为ListView控件提供编辑、插入、删除一条数据项的操作。


要使用户可以编辑数据,我们可以向ListView添加一个EditItemTemplate模板。当选定项切换到编辑模式的时候ListView控件使用EditItemTemplate模板来显示此项。该模板在用户编辑时应该包含绑定了数据的可输入控件。例如,TextBox控件。


要使用户可以编辑数据,我们可以向ListView添加一个InsertItemTemplate模板。与EditItemTemplate控件一样,该模板包含绑定了数据的可输入控件。通过指定InsertItemPosition 属性InsertItemTemplate模板可以选择显示在开头或者结尾部分。


我们可以向ItemTemplate、SelectedItemTemplate与AlternatingItemTemplate模板添加一个编辑按钮来使用户可以切换到编辑模式。在EditItemTemplate模板中我们可以添加更新按钮来使用户可以保存数据。同样也可以添加一个取消按钮来使用户可以不保存数据切换回显示模式。


我们可以通过为按钮设置CommandName属性来定义一个动作。下面列出了ListView控件内建的ComandName属性名称。


Select


为选中的项显示SelectedItemTemplate模板中的内容。
Insert


在InsertItemTemplate模板中,保存被指定的数据绑定控件。
Edit


使ListView可以进入编辑模式,并显示EditItemTemplate中的项。
Update


在EditItemTemplate模板中,使被绑定的控件可以保存到数据源。
Delete


删除数据项。
Cancel


取消当前的动作。或清空InsertItemTemplate中的控件值。
插入:


使用InsertItemTemplate模板在ListView中自定义插入界面来实现数据的插入。InsertItemTemplate一般包含一些为用户提供新记录输入的可输入控件。并且通常它也包含实现插入或取消操作的按钮控件。


向ListView中添加一个InsertItemTemplate模板。通过使用实现了双向绑定的可输入控件来建立与字段的关联。当一条数据被插入以后,ListView控件自动从可输入控件来获取字段的值。


要创建实现了内建插入与取消操作的控件,需要向模板中添加一个按钮。并设置CommandName属性为"Cancel"或"Insert"。


我们可以通过设置ListView控件的InsertItemPostion属性自由的设置插入项的位置。


看一段InsertItemTemplate的例子.







AssociatedControlID="FirstNameTextBox" Text="First Name"/>
Text='<%#Bind("FirstName") %>' />

AssociatedControlID="LastNameTextBox" Text="Last Name" />
Text='<%#Bind("LastName") %>' />

AssociatedControlID="EmailTextBox" Text="E-mail" />
Text='<%#Bind("EmailAddress") %>' />




CommandName="Insert" Text="Insert" />





其中的TextBox控件就是我们所说的双向绑定控件。

编辑:


通过向ItemTemplate、SelectedItemTemplate与AlternatingItemTemplate中添加按钮,并将按钮CommandName属性定义为"Edit" ,ID定义为"EditButton"。通过点击按钮来启动编辑状态。下面是AlternatingItemTemplate中的示例。










//后面的代码省略


使用EditItemTemplate模板在ListView中自定义数据编辑模式。EditItemTemplate一般包含一些为用户提供记录修改的可输入控件。并且通常它也包含实现更新或取消操作的按钮控件。


向ListView中添加一个EditItemTemplate模板。通过使用实现了双向绑定的可输入控件来建立与字段的关联。当一条数据被插入以后,ListView控件自动从可输入控件来获取字段的值。


要创建实现了内建更新与取消操作的控件,需要向模板中添加一个按钮。并设置CommandName属性为"Cancel"或" Update "。
EditItemTemplate模板举例:







&nbsp;





MaxLength="50" />





MaxLength="50" />









删除:


通过向ItemTemplate、SelectedItemTemplate与AlternatingItemTemplate中添加按钮,并将按钮CommandName属性定义为" Delete ", ID定义为" DeleteButton "。通过点击按钮来启动删除事件。


下面是AlternatingItemTemplate中的示例。










//后面的代码省略




深入:使用ListView来显示父子表关系实现父子表的关系,嵌套的数据显示是一种不错的方法。ListView来实现数据的嵌套可以说是小菜一叠。只需要在ItemTemplate中再放入一个ListView就可以了,或其它的数据控件。



来看看例子吧: HTML Code




Untitled Page





EnableViewState="False" OnSorting="ListView1_Sorting">








CategoryID

CategoryName

Description

ProductID

ProductName

UnitPrice


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