Repeater:

HeaderTemplate - 在加载开始执行一遍

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

FooterTemplate - 在加载最后执行一遍

AlternatingItemTemplate - 交替项模板

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="lianxi.aspx.cs" Inherits="lianxi" %>
  2.  
  3. <!DOCTYPE html>
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  8. <title></title>
  9. </head>
  10. <body>
  11. <form id="form1" runat="server">
  12. <asp:Repeater ID="Repeater1" runat="server">
  13. <HeaderTemplate>
  14. <table style="text-align:center">
  15. <tr style="color:white;padding:10px;">
  16. <td>UserName</td>
  17. <td>PsssWord</td>
  18. <td>NickName</td>
  19. <td>Sex</td>
  20. <td>Birthday</td>
  21. <td>Nation</td>
  22. </tr>
  23. </HeaderTemplate>
  24. <ItemTemplate>
  25. <tr style=" line-height: 1.5 !important;">">
  26. <td><%#Eval("UserName")%></td>
  27. <td><%#Eval("PassWord")%></td>
  28. <td><%#Eval("NickName")%></td>
  29. <td><%#Eval("Sex")%></td>
  30. <td><%#Eval("birthday")%></td>
  31. <td><%#Eval("Nation")%></td>
  32. </tr>
  33. </ItemTemplate>
  34. <FooterTemplate>
  35. </table>
  36. </FooterTemplate>
  37. </asp:Repeater>
  38.  
  39. </form>
  40. </body>
  41. </html>
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. if (!IsPostBack)
  4. {
  5. Repeater1.DataSource = new UsersDA().Select();
  6. Repeater1.DataBind();
  7. }
  8. }

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

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

  1. /// <summary>
  2. /// 性别
  3. /// </summary>
  4. public bool Sex
  5. {
  6. get { return _Sex; }
  7. set { _Sex = value; }
  8. }
  9.  
  10. public string SexStr
  11. {
  12. get { return _Sex ? "男" : "女"; }
  13. }
  14.  
  15. private DateTime _Birthday;
  16.  
  17. /// <summary>
  18. /// 生日
  19. /// </summary>
  20. public DateTime Birthday
  21. {
  22. get { return _Birthday; }
  23. set { _Birthday = value; }
  24. }
  25.  
  26. public string BirthdayStr
  27. {
  28. get { return _Birthday.ToString("yyyy年MM月dd日"); }
  29. }
  30.  
  31. private string _Nation;
  32.  
  33. /// <summary>
  34. /// 民族
  35. /// </summary>
  36. public string Nation
  37. {
  38. get { return _Nation; }
  39. set { _Nation = value; }
  40. }
  41.  
  42. public string NationName
  43. {
  44. get { return new NationData().Select(this._Nation).NationName; }
  45.  
  46. }
  47.  
  48. public string Age
  49. {
  50. get { return (DateTime.Now.Year - this._Birthday.Year).ToString(); }
  51. }
  52.  
  53. public string Red
  54. {
  55. get
  56. {
  57. string end = "";
  58. if (Convert.ToInt32(Age) >= 16)
  59. {
  60. end = "";
  61. }
  62. return end;
  63. }
  64. }
  1. <ItemTemplate>
  2. <tr class="tr_Item" style="<%#Eval("Red")%>">
  3. <td><%#Eval("UserName") %></td>
  4. <td><%#Eval("PassWord") %></td>
  5. <td><%#Eval("NickName") %></td>
  6. <td><%#Eval("SexStr") %></td>
  7. <td><%#Eval("BirthdayStr") %></td>
  8. <td><%#Eval("Age") %></td>
  9. <td><%#Eval("NationName") %></td>
  10. </tr>
  11. </ItemTemplate>

光棒效果

鼠标移入改变颜色

  1. <style type="text/css">
  2. #tb1 {
  3. width: 100%;
  4. background-color: navy;
  5. text-align: center;
  6. }
  7.  
  8. #tr_head {
  9. color: white;
  10. }
  11.  
  12. .tr_Item {
  13. background-color: white;
  14. }
  15.  
  16. .tr_Item2 {
  17. background-color: #e0e0e0;
  18. }
  19. </style>
  20. <script type="text/javascript">
  21. window.onload = function () {
  22. var items = document.getElementsByClassName("tr_Item");
  23. var oldColor = "";
  24. for (var i = 0; i < items.length; i++) {
  25. items[i].onmouseover = function () {
  26. oldColor = this.style.backgroundColor;
  27. this.style.backgroundColor = "yellow";
  28. };
  29. items[i].onmouseout = function () {
  30. this.style.backgroundColor = oldColor;
  31. };
  32.  
  33. }
  34.  
  35. };
  36. </script>

webform repeater控件的更多相关文章

  1. Webform(Repeater控件)

    一.Repeater控件 有五大模板 ItemTemplate :有多少条数据,执行多少遍        AlternatingItemTemplate : 对交替数据项进行格式设置       Se ...

  2. WebForm(四)——Repeater控件(重要、好用)

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

  3. Webform中Repeater控件--绑定嵌入C#代码四种方式

    网页里面嵌入C#代码用的是<% %>,嵌入php代码<?php ?> 绑定数据的四种方式: 1.直接绑定 <%#Eval("Code") %> ...

  4. 【2017-05-18】WebForm的Repeater控件和一些简单控件

    一.Repeater控件 1. <%@ %> - 这里面写一些声明和引用的 <%  %> - 编写C#代码的 <%= %> - 往界面上输出一个变量的值 <% ...

  5. 【2017-05-18】WebForm的Repeater控件及简单控件

    <%@ %> - 这里面写一些声明和引用的 <%  %> - 编写C#代码的 <%= %> - 往界面上输出一个变量的值 <%# Eval("属性名 ...

  6. webform之Repeater控件

    一.Repeater控件 数据循环编辑 1.repeater包括五大模板: (1)HeaderTemplate:标题模板,对开头进行编辑,只执行一次 (2)FooterTemplate:页尾结束模板, ...

  7. ASP.Net中通过Jquery前端对Repeater控件绑定的数据进行操作

    说明:由于Repeater控件是动态绑定,通过Id获取数据只能默认获取第一行: 1.对Repeater中div设置样式 2.通过$(".css").each(function(){ ...

  8. Repeater 控件

    Repeater 控件是一个容器控件,可用于从网页的任何可用数据中创建自定义列表.Repeater 控件没有自己内置的呈现功能,这意味着用户必须通过创建模板来提供 Repeater 控件的布局.当网页 ...

  9. Repeater控件用法

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Repeater.aspx. ...

随机推荐

  1. overflow 清除浮动

    对overflow的理解还停留在“规定当内容溢出元素框时发生的事情”,这种简单的认识上,今天发现overflow还可以清除浮动. <style> .outside{ height:auto ...

  2. 【转】精心推荐几款超实用的 CSS 开发工具

    原文转自:http://www.html5cn.org/article-5741-1.html 摘要: 当你开发一个网站或 Web 应用程序的时候,有合适的工具,绝对可以帮助您节省大量的时间.在这篇文 ...

  3. phpstorm 激活

    http://idea.lanyus.com/

  4. 编写更好的jQuery代码的建议(share)

    留个备份! 原文链接: Mathew Carella   翻译: 伯乐在线- yanhaijing译文链接: http://blog.jobbole.com/52770/ 讨论jQuery和javas ...

  5. 初学Html

    HTML,超文本标记语言,文本解释性语言,它的源代码不通过编译而直接在浏览器中运行时被翻译,其决定的是网页的结构和内容. 一谈html,自然首先是浏览器,比较具有代表性的浏览器则是谷歌.火狐.IE.苹 ...

  6. java Scanner

    public static void main(String[] args) throws IOException { System.out.print("Enter a number:&q ...

  7. 034. asp.netWeb用户控件之三通过用户控件实现用户注册和登录

    用户控件login.ascx代码: <%@ Control Language="C#" AutoEventWireup="true" CodeFile=& ...

  8. 数据库之mysql存储程序

    什么时候会用到存储过程 1.存储过程只在创造时进行编译,以后每次执行存储过程都不需再重新编译,而一般 SQL 语句每执行一次就编译一次,所以使用存储过程可提高数据库执行速度2.当对数据库进行复杂操作时 ...

  9. Unity Shader——Writing Surface Shaders(2)——Custom Lighting models in Surface Shaders

    Surface Shader中的自定义光照模型 当你在编写 Surface Shaders 时,是在描述一个表面的属性(反射颜色.法线……),而且光的交互过程是由一个光照模型来计算的.内建的光照模型有 ...

  10. python模块介绍- SocketServer 网络服务框架

    来源:https://my.oschina.net/u/1433482/blog/190612 摘要: SocketServer简化了网络服务器的编写.它有4个类:TCPServer,UDPServe ...