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

Reading number is top 10 articles
在ASP.NET中利用VWD操作数据库简介_[Asp.Net教程]
asp.net2.0导出pdf文件完美解决方案_[Asp.Net教程]
ASP.NET中Cookie的使用介绍_[Asp.Net教程]
visual c++中的构造函数与析构函数
计算两者相差几个月零几天_[PHP教程]
asp.net中对数据库表插入null空值的问题_.net资料_编程技术
Ajax标签导航实例详解-Javascript技巧篇_[AJAX教程]
ASP.NET教程:AccessDataSource的使用_[Asp.Net教程]
SQL,Server,全局变量_mssql学习_编程技术
利用ICallbackEventHandle实现类似AJAX的无刷新页面_[Asp.Net教程]
Reading number is top 10 pictures
The Soviet union swimsuit exposure in the 70 year3
I also want to live a June 1 children's day, dad
男人们都在想什么
Men's and women's orgasms
Startling Russian girl blind date scene1
Discharge accidentally Actresses by the breast4
一千块钱如何创业
The real super beauty11
The real super beauty9
In the world the most mysterious 21 place landscape2
Download software ranking
Tram sex maniac 2 (H) rar bag17
Tram sex maniac 2 (H) rar bag18
Professional killers2 for Android
Tram sex maniac 2 (H) rar bag16
linux安装大全
WebService在.NET中的实战应用教学视频 → 第5集
终极变速大师Speeder3.26
Unix video tutorial19
天龙八部十二宫服务端
网络管理员第三版
归海一刀 published in(发表于) 2014/1/30 1:58:00 Edit(编辑)
详细介绍datalist用法_[Asp.Net教程]

详细介绍datalist用法_[Asp.Net教程]

详细介绍datalist用法_[Asp.Net教程]
设计模版:
页眉


页脚


数据记录



交替显示项


选中时的显示方式


编辑时的显示方式


数据记录分隔符


编辑模版,里面可以嵌入控件,绑定数据。






<%# DataBinder.Eval(Container.DataItem, "持股名称") %>


<%# DataBinder.Eval(Container.DataItem, "市值", "{0:n}") %>


<%# DataBinder.Eval(Container.DataItem, "净值", "{0:n}") %>







设置外观
RepeatLayout 属性设置显示方式
RepeatDirection 显示方向
RepeatColumns 列数

事件
加入模版列的按钮会将其click事件反升到 ItemCommand 事件,也可设置 CommandName
来响应不同的事件,如设为:edit,即引发EditCommand()等。
注:若设为:select 则会引发SelectedIndexChanged 和ItemCommand事件
SelectedItemTemplate模版; 添加详细信息的控件,当用户选择了该项,选择模版则显示。
private void DataList1_ItemCommand(……)
{ switch(e.CommandName)
{
case "select":
this.DataList1.SelectedIndex=e.Item.ItemIndex;
string s=(string)this.DataList1.DataKeys[e.Item.ItemIndex];
//在此获得该条记录的详细数据,在SelectedItemTemplate模版里显示。
break;
case "unselect":
this.DataList1.SelectedIndex=-1;
break;
}
this.DataList1.DataBind();//一定要
}

EditItemTemplate模版
编辑:
this.DataList1.EditItemIndex=e.Item.ItemIndex;
this.DataList1.DataBind();
更新:
得到主键
string s=(string)this.DataList1.DataKeys[e.Item.ItemIndex];
得到模版里的控件
TextBox box=(TextBox)e.Item.FindControl("TextBox1");
更新记录
this.DataList1.DataBind();
取消:
this.DataList1.EditItemIndex=-1;
this.DataList1.DataBind();
删除项
一次勾选多条记录,一次删除
foreach(DataListItem i in this.DataList1.Items)
{

bool IsChecked=((CheckBox)i.FindControl("deletectr")).Checked;

if(IsChecked)
{
string s=(string)this.DataList1.DataKeys[e.Item.ItemIndex];

删除操作 }

}
运行中自定义DataList控件
//当创建DataList控件中的任意项时
private void DataList1_ItemCreated(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
switch(e.Item.ItemType)
{ case ListItemType.Header:
e.Item.ForeColor=Color.Red;
e.Item.BackColor=Color.Black;
break;
case ListItemType.Item:
e.Item.BackColor=Color.Black;
break;
}
}
//当模版中的项被数据绑定时发生,数据被显示到客户端前加以访问的最后机会
private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if((e.Item.ItemType==ListItemType.Header)||(e.Item.ItemType==ListItemType.Item))
{
System.Data.Common.DbDataRecord drv=
(System.Data.Common.DbDataRecord)e.Item.DataItem;
if((decimal)drv["库存量"]<1000)
{
e.Item.ForeColor=Color.Red;
}
}

}

另种方式
if((e.Item.ItemType==ListItemType.Header)||(e.Item.ItemType==ListItemType.Item))

{
DataRowView drv=(DataRowView)e.Item.DataItem;
string department=(string)drv["部门"];
switch(department)
{ case "销售部":

e.Item.BackColor=Color.Black;

break;
case "技术部":
e.Item.BackColor=Color.Red;
break; }
}


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