Repeater控件的ItemDataBound事件
Repeater控件的ItemDataBound事件:在项被绑定数据后触发。
下面的例子来自msdn,不过我把前台和后台分开了。
前台是:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"><title></title> </head> <body><h1>Repeater控件的ItemDataBound事件</h1><form id="form1" runat="server"><div><asp:Repeater ID="repeater1" runat="server" OnItemDataBound="Repeater1_OnItemDataBound"><HeaderTemplate> <table border="1"> <tr><td><b>Product</b></td><td><b>Consumer Rating</b></td></tr> </HeaderTemplate><ItemTemplate> <tr><td><asp:Label Text='<%#Eval("ProductID") %>' runat="server"></asp:Label></td><td><asp:Label Text='<%#Eval("Rating") %>' ID=RatingLabel runat="server"></asp:Label></td></tr> </ItemTemplate><FooterTemplate></table> </FooterTemplate></asp:Repeater></div></form> </body> </html>
注意:table开始标签在<HeaderTemplate>中,结束标签在 <FooterTemplate>中。
绑定数据Text='<%#Eval("ProductID") %>'需要加单引号,里面加双引号。
后台是:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Collections;namespace WebApplication2 {public partial class WebForm1 : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){ArrayList values = new ArrayList();values.Add(new Evaluation("Razor Wiper Blades", "Good"));values.Add(new Evaluation("Shoe-So-Soft Softening Polish", "Poor"));values.Add(new Evaluation("DynaSmile Dental Fixative", "Fair"));this.repeater1.DataSource = values;//指定数据源this.repeater1.DataBind(); //绑定数据 }protected void Repeater1_OnItemDataBound(object sender, RepeaterItemEventArgs e){// This event is raised for the header, the footer, separators, and items.// Execute the following logic for Items and Alternating Items.if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){if (((Evaluation)e.Item.DataItem).Rating == "Good"){((Label)e.Item.FindControl("RatingLabel")).Text = "<b>***Good***</b>";}}}}public class Evaluation{private string productid;private string rating;public Evaluation(string productid, string rating){this.productid = productid;this.rating = rating;}public string ProductID{get{return productid;}}public string Rating{get{return rating;}}} }
该事件在 Repeater 控件中的某一项被数据绑定后但尚未呈现在页面上之前发生。
运行结果:
参见:http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.repeater.itemdatabound(v=vs.80).aspx
下面说一下RepeaterItemEventArgs,它为 Repeater 的 ItemCreated 和 ItemDataBound 事件提供数据。
如果在 Repeter中有一个DropDownlist and Datalist ,然后你想根据DropDownlist的值设置Datalist的值,可以使用下面的方法来传值:
protected void DDLSort2_OnSelectedIndexChanged(object sender, EventArgs e){DropDownList dl = new DropDownList();dl = (DropDownList)sender;string sortdir = dl.SelectedValue.ToString();Control parent = dl.Parent;RepeaterItem rep = new RepeaterItem(0,ListItemType.Item);rep = (RepeaterItem)parent;RepeaterItemEventArgs e1=new RepeaterItemEventArgs(rep);BindInnerDatalist(sender,e1, sortdir);//另外写的方法。}
参见:http://forums.asp.net/t/1707348.aspx/1
转载于:https://www.cnblogs.com/wang7/archive/2012/10/09/2716492.html
Repeater控件的ItemDataBound事件相关推荐
- Repeater控件
Repeater控件和DataList控件,可以用来一次显示一组数据项.比如,可以用它们显示一个数据表中的所有行. Repeater控件完全由模板驱动,提供了最大的灵活性,可以任意设置它的输 ...
- asp.net学习之Repeater控件
Repeater控件和DataList控件,可以用来一次显示一组数据项.比如,可以用它们显示一个数据表中的所有行. Repeater控件完全由模板驱动,提供了最大的灵活性,可以任意设置它的输 ...
- onmouseover和onmouseout在Repeater控件中应用
如果你曾看过这篇,http://www.cnblogs.com/insus/articles/1411057.html ,它是在GridView控件中演示,但是它的方法在Repeater控件是无法复制 ...
- Repeater控件使用总结
以前喜欢用gridview来显示数据,在面试一家外包公司时,他们对gridview嗤之以鼻,说:"微软很多自己的控件都不用,控件只是为了入门,我们只用repeater",我不知道g ...
- Repeater控件动态变更列(Header,Item和Foot)信息
需求开发一个小报表,显示最近五个月的summary的数量统计,报表会随月份的变化而变化,如下图.第一列[Department]固定,第二至第六列,也就是说Nov 2012 这列会在下月的时候消失,其后 ...
- repeater 控件ajax绑定数据源,【ASP.NET】第九课——使用DataList控件和Repeater控件绑定数据...
知识点:掌握 DataList 控件呈现数据的方法: 掌握 Repeater 控件呈现数据的方法:掌握处理 Repeater 控件中的按钮事件. 1. 使用 DataList 控件呈现数据 在用 AS ...
- 在 DataList 和 Repeater 控件中定制按钮46
简介 在前面十七个DataList 控件和 Repeater 控件教程中,我们创建了一些只读示例和一些编辑和删除示例.要在 DataList 控件中方便地进行编辑和删除,我们为 DataList 控件 ...
- Tip:在使用AjaxControlTookit的控件时响应事件
我谈到了使用AjaxControlTookit中控件的关键是客户端的各Behavior组件.微软官方推出的示例都太过于重视演示效果,而忽略了实际使用中的问题--市场需要吧,要让技术看上去吸引人,这么做 ...
- aspx repeater 用法_详解ASP.NET数据绑定操作中Repeater控件的用法
一.绑定控件之Repeater.NET封装了多种数据绑定控件,诸如GridView.DataList等但该篇文章将会从Repeater入手,因为Repeater只提供了基本的数据绑定模板,没有内置其它 ...
最新文章
- Neo4j实战 (数据库技术丛书)pdf
- 《图解CSS3:核心技术与案例实战》——1.3节渐进增强
- 如何在Photoshop中制作双曝光图像
- 10-3的随笔继续讲,演绎“圆弧底”
- LeetCode(908)——最小差值 I(JavaScript)
- 好用的jquery选择器
- erp 维护费 要交吗_ERP系统实施费用!
- zoj3829 Known Notation --- 2014 ACM-ICPC Asia Mudanjiang Regional Contest
- mysql5.6跳过密码登录_mysql-配置与使用(跳过原始密码登陆)
- bash给脚本加进度条_shell脚本进度条。
- 快速读懂CAN报文 DBC文件 解析文件
- Raid0/raid1/raid5磁盘阵列数据恢复思路
- python有哪两种表现形式小练笔_写一篇不一样的爱400字:爱有两种表现形式小练笔400字...
- 如何买到便宜点的书(知乎)
- 《东周列国志》第十三回 鲁桓公夫妇如齐 郑子亹君臣为戮
- Windows批处理文件bat学习(一)
- 欧拉计划第80题:平方根数字展开
- 苹果手机性能测试用是么软件,怎么检测iPhone手机性能
- linux 备份文件滚动删除
- 【Linux 操作系统】Ubuntu 基础操作 基础命令 热键 man手册使用 关机 重启等命令使用
热门文章
- word操作实例:解除文档编辑限制的2个方法
- 字符流与字节流的区别
- Pytorch 训练与测试时爆显存(out of memory)的一个解决方案
- 操作符详解(所有操作符的所有使用方法)
- getline函数解析
- java获取当前request_java如何在一个普通的类中获取request对象
- js截取url里面的值
- 洛谷刷题C语言:远古档案馆(Ancient Archive)、VOLIM、SAHOVNICA、Tuna、KRIŽALJKA
- ffmpeg 提取视频中音轨为高码率mp3文件
- 计算机组成与结构ppt,计算机组成与结构讲义.ppt