Repeater:

HeaderTemplate: 在加载开始执行一遍

ItemTemplate : 有多少条数据,执行多少遍

FooterTemplate :在加载最后执行一遍

AlternatingItemTemplate : 交替项模板

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table style="background-color:navy;text-align:center">
<tr style="color:white;padding:10px;">
<td>UserName</td>
<td>PsssWord</td>
<td>NickName</td>
<td>Sex</td>
<td>Birthday</td>
<td>Nation</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:yellow">
<td><%#Eval("UserName")%></td>
<td><%#Eval("PassWord")%></td>
<td><%#Eval("NickName")%></td>
<td><%#Eval("Sex")%></td>
<td><%#Eval("birthday")%></td>
<td><%#Eval("Nation")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater> </form>
</body>
</html>

数据绑定

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Repeater1.DataSource = new UsersDA().Select();
Repeater1.Users:
/// <summary>
/// 性别
/// </summary>
public bool Sex
{
get { return _Sex; }
set { _Sex = value; }
} public string SexStr
{
get { return _Sex ? "男" : "女"; }
} private DateTime _Birthday; /// <summary>
/// 生日
/// </summary>
public DateTime Birthday
{
get { return _Birthday; }
set { _Birthday = value; }
} public string BirthdayStr
{
get { return _Birthday.ToString("yyyy年MM月dd日"); }
} private string _Nation; /// <summary>
/// 民族
/// </summary>
public string Nation
{
get { return _Nation; }
set { _Nation = value; }
} public string NationName
{
get { return new NationData().Select(this._Nation).NationName; } } public string Age
{
get { return (DateTime.Now.Year - this._Birthday.Year).ToString(); }
} public string Red
{
get
{
string end = "";
if (Convert.ToInt32(Age) >= )
{
end = "background-color:red;";
}
return end;
}
}

数据操作类

public class UsersDA
{
SqlConnection conn = null;
SqlCommand cmd = null;
public UserDA()
{
conn = new SqlConnection("server=.;database=Data0617;user=sa;pwd=123");
cmd = conn.CreateCommand();
}
public List<Users> select()
{
List<Users> list = new List<Users>();
cmd.CommandText = "select * from Users";
conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows)
{
while (dr.Read())
{
Users data = new Users();
data.UserName = dr[].ToString();
data.Password = dr[].ToString();
data.NickName = dr[].ToString();
data.Sex =Convert.ToBoolean( dr[]) ;
data.Birthday = Convert.ToDateTime(dr[]);
data.Nation = dr[].ToString();
list.Add(data);
}
}
conn.Close(); return list;
} }

库存预警

通过某个属性值判断后,将某条数据的样式进行更改

属性扩展的方式,写一个返回string类型的属性,返回的是CSS样式表样式

为了让大家知道,属性值不一定非得是展示用

<ItemTemplate>
<tr class="tr_Item" style="<%#Eval("Red")%>">
<td><%#Eval("UserName") %></td>
<td><%#Eval("PassWord") %></td>
<td><%#Eval("NickName") %></td>
<td><%#Eval("SexStr") %></td>
<td><%#Eval("BirthdayStr") %></td>
<td><%#Eval("Age") %></td>
<td><%#Eval("NationName") %></td>
</tr>
</ItemTemplate>

光棒效果

鼠标移入改变颜色

<style type="text/css">
#tb1 {
width: %;
background-color: navy;
text-align: center;
} #tr_head {
color: white;
} .tr_Item {
background-color: white;
} .tr_Item2 {
background-color: #e0e0e0;
}
</style>
<script type="text/javascript">
window.onload = function () {
var items = document.getElementsByClassName("tr_Item");
var oldColor = "";
for (var i = ; i < items.length; i++) {
items[i].onmouseover = function () {
oldColor = this.style.backgroundColor;
this.style.backgroundColor = "yellow";
};
items[i].onmouseout = function () {
this.style.backgroundColor = oldColor;
}; } };
</script>

WebForm Repeater使用的更多相关文章

  1. Webform——Repeater多表联合显示

    对于一个表里,通过外键连接如何显示另一个表的数据,前Winform里可以用封装类来实现. 对于Webform,可以用封装类,也可以用Repeater的ItemDataBound事件(//在项被绑定数据 ...

  2. webform Repeater重复器、地址栏传值、Response

    Repeater: 重复器 <HeaderTemplate></HeaderTemplate> - 头模板:在循环开始时,其内容只会打印一遍 <ItemTemplate& ...

  3. webform Repeater、地址栏传值、Response

    Repeater: 重复器 Repeater中有五个模板,这里需要注意的是4个 <HeaderTemplate> - 开头,只执行一次的内容 <ItemTemplate> - ...

  4. WebForm Repeater: 重复器

    Repeater控件,可以用来一次显示一组数据项.比如,可以用它们显示一个数据表中的所有行.             Repeater控件完全由模板驱动,提供了最大的灵活性,可以任意设置它的输出格式. ...

  5. WebForm Repeater Response以及 地址栏

    Repeater重复器: Repeater中有五个模板,这里需要注意的是4个 <HeaderTemplate> - 开头,只执行一次的内容 <ItemTemplate> - 需 ...

  6. webform repeater控件

    Repeater: HeaderTemplate - 在加载开始执行一遍 ItemTemplate - 有多少条数据,执行多少遍 FooterTemplate - 在加载最后执行一遍 Alternat ...

  7. Webform Repeater的灵活运用

    案例:模拟购物列表 封装实体类:   数据访问类: 用Repeater展示: 1 <%@ Page Language="C#" AutoEventWireup="t ...

  8. WebForm Repeater的事件、后天数据展示--2017年1月8日

    Repeater的Command操作 1.ItemCommand事件 :在Repeater中所有能触发事件的控件,都会来触发这一个事件 CommandName : 判断点击的是什么按钮,e.Comma ...

  9. webform repeater

    repeater:由模板构成,解析后模板就不存在了             需要指定数据源进行数据绑定 List<Fruit> list = new FruitDA().Select(); ...

随机推荐

  1. 深入分析@Transactional的用法

    关键词:事务, 编程式事务,声明式事务.spring 事务管理.AOP事务增强.@Transactional 在分析深入分析@Transactional的使用之前,我们先回顾一下事务的一些基本内容. ...

  2. compass color 颜色 对比色[Sass和compass学习笔记]

    最基本的api 是对比色,对与我这种菜鸟来说,没有什么比在一个背景色下 用什么颜色的文字坑蛋疼的事情了,这个工具可以帮助大家很好解决这个问题 api 地址 http://compass-style.o ...

  3. apace日常操作和配置

    [root@limt modules]# /usr/sbin/apachectl -h Usage: /usr/sbin/httpd [-D name] [-d directory] [-f file ...

  4. CentOS7下安装chrome浏览器

    在CentOS 7环境下安装chrome浏览器 1.修改yum源 在/etc/yum.repos.d/目录下新建文件google-chrome.repo,向其中添加如下内容: [google-chro ...

  5. likely && unlikely in GCC

    在linux内核源码或一些比较成熟的c语言架构源码中,我们常会见到类似下面的代码: if (unlikely(!packet)) { return res_failed; } // OR if (li ...

  6. css 居中问题

    水平居中有text-align:center 和 margin:0 auto,前者是针对父元素进行设置而后者则是对子元素.margin:0 auto; 这里实现的前提是子元素没有float 浮动起来, ...

  7. WordPress基础:自定义菜单

    需要自定义一个菜单,可以访问后台->外观->菜单

  8. GC

    垃圾回收机制的优点:释放无用的对象所占用的空间.方式:自动回收.手动回收.使用System.gc实际上是调用Runtime.getRuntime().gc()

  9. JMeter学习-028-JMeter默认jmx脚本分发目录(路径)定制

    我们在分布式执行参数化脚本时,为尽可能多的利用Slave资源,尽可能将参数文件配置为相对路径,以更好的去适配Slave环境.与此同时,每台Slave的服务jmeter -s 启动的路径可能不尽相同,同 ...

  10. 发布Live Writer代码着色插件CNBlogs.CodeHighlighter

    在解决了使用Windows Live Writer发博所遇到的"建分类.加标签.写摘要"与"设置EntryName"的四个问题之后,我们趁热打铁,解决了第五个问 ...