案例:模拟购物列表

封装实体类:

 

数据访问类:

用Repeater展示:

  1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2
3 <!DOCTYPE html>
4
5 <html xmlns="http://www.w3.org/1999/xhtml">
6 <head id="Head1" runat="server">
7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8 <title></title>
9 <style>
10 * {
11 padding: 0px;
12 margin: 0px;
13 }
14
15 #header {
16 position: relative;
17 width: 100%;
18 height: 80px;
19 background-color: navy;
20 }
21
22 #footer {
23 position: relative;
24 width: 100%;
25 height: 100px;
26 background-color: black;
27 }
28
29 #items {
30 position: relative;
31 width: 80%;
32 margin-left: 10%;
33 }
34
35 .item {
36 position: relative;
37 width: 23.5%;
38 margin-left: 0.5%;
39 margin-right: 0.5%;
40 height: 300px;
41 border: 1px solid black;
42 margin-top: 5px;
43 margin-bottom: 5px;
44 float: left;
45 }
46
47 .item img {
48 position: relative;
49 width: 100%;
50 height: 60%;
51 }
52
53 .item-name {
54 position: relative;
55 width: 80%;
56 margin-left: 10%;
57 font-size: 18px;
58 }
59
60 .item-price {
61 position: relative;
62 width: 100%;
63 color: red;
64 text-align: right;
65 font-size: 18px;
66 }
67
68 .item-price span {
69 font-size: 12px;
70 text-decoration: line-through;
71 }
72
73 .item-context {
74 position: relative;
75 width: 90%;
76 margin-left: 5%;
77 }
78
79 #Label1 {
80 color: white;
81 }
82 </style>
83
84 </head>
85 <body style="font-family: 微软雅黑;">
86 <form id="form1" runat="server">
87 <div id="header"></div>
88 <div id="items">
89 <asp:Repeater ID="Repeater1" runat="server">
90 <ItemTemplate>
91 <div class="item">
92 <img src="<%#Eval("pic") %>" />
93 <div class="item-name"><%#Eval("name") %></div>
94 <div class="item-price">价格:<%#Eval("nowPrice") %><span><%#Eval("oldPrice") %></span></div>
95 <div class="item-context"><%#Eval("context") %></div>
96 <asp:Button ID="Button1" runat="server" Text="删除" CommandName="Delete" CommandArgument='<%#Eval("ids") %>' />
97 </div>
98 </ItemTemplate>
99 </asp:Repeater>
100 <div style="clear: both;"></div>
101 </div>
102
103 <div id="footer"></div>
104 </form>
105 </body>
106 </html>
 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.UI;
6 using System.Web.UI.WebControls;
7
8 public partial class _Default : System.Web.UI.Page
9 {
10 protected void Page_Load(object sender, EventArgs e)
11 {
12 if (!IsPostBack)
13 {
14 Repeater1.DataSource = new gouwuData().Select();
15 Repeater1.DataBind();
16 }
17 //点击Repeater1中的按钮时发生
18 Repeater1.ItemCommand += Repeater1_ItemCommand;
19 }
20
21 void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
22 {
23 if (e.CommandName == "Delete")
24 {
25 new gouwuData().Delete(Convert.ToInt32(e.CommandArgument));
26
27 Repeater1.DataSource = new gouwuData().Select();
28 Repeater1.DataBind();
29 }
30 }
31 }

不用Repeater展示:

Repeater的Command操作

1、ItemCommand事件 :在Repeater中所有能触发事件的控件,都会来触发这一个事件

 后台创建:在Page_Load中  Repeater1.ItemCommand +=  ,然后双击Tab键创建

2、CommandName : 判断点击的是什么按钮,

后台调用:e.CommandName

3、CommandArgument : 触发事件所传递过来的主键值数据,放在这里面 界面值绑定时要用  单引号 !!!!!!

后台调用:e.CommandArgument 

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使用

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

  6. WebForm Repeater Response以及 地址栏

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

  7. webform repeater控件

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

  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. LeetCode【第217题】Contains Duplicate

    题目: ''' Given an array of integers, find if the array contains any duplicates. Your function should ...

  2. 进位位(carry)与溢出位(overflow)的区别

    处理器内部以补码表示有符号数,8个二进制位能够表达的整数范围是:+127 ~ -128,16位表达的范围是:+32767 ~ -32768.如果运算结果超出了这个范围,就是产生了溢出:有溢出,说明有符 ...

  3. 基础canvas应用-钟表绘制

    首先,canvas语法基础薄弱的小伙伴请点这里,剩下的小伙伴们可以接着往下看了. 一个表,需要画什么出来呢:3条线(时分秒针),1个圆(表盘),以及60条短线/点(刻度). 嗯,没毛病. 那接下来让我 ...

  4. 双积分式(A/D)转换器电路结构及工作原理

    1.转换方式 V-T型间接转换ADC. 2.  电路结构 图1是这种转换器的原理电路,它由积分器(由集成运放A组成).过零比较器(C).时钟脉冲控制门(G)和计数器(ff0-ffn)等几部分组成 图1 ...

  5. 在ios开发中有多少常用的加密解密方式(备用)

    最常用的是MD5和base64编码,还有DES 3DES AES加密 ios怎么实现RAS加密解密 最近几天折腾了一下如何在iOS上使用RSA来加密.iOS上并没有直接的RSA加密API.但是iOS提 ...

  6. pythom 安装MySQL-pythom的问题

    链接一:http://blog.csdn.net/dqatsh/article/details/2418663 链接二:http://codingnow.cn/language/159.html 链接 ...

  7. 如何通过REST获取JENKINS的编译进度?

    第二版功能需要实现, 我看了一下,获取百分比进度不太可能了,,因为JENKINS本身都没有具体的百分比进度.. 那,,只好实现获取实时值,如果完成就显示完成. URL: http://1.2.3.4/ ...

  8. HDU 3308 LCIS 线段树区间更新

    最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛  ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...

  9. awsomeplayer结构认识

    把这个搞明白,算是顿悟的一个真实例子.怎么也搞不懂的架构,突然就想明白了.不过这其实是一个思维的过程. 当然如果你想明白这些东西,至少要非常清楚一个概念:接口. 我只是一个半路出家的开发者,我真正明白 ...

  10. VS2012中使用纯C实现COM的小问题

    用VS2012新建C++工程都预定义了宏__cplusplus,所以引用到的都是C++的定义.但是要用C实现的话,一般都是也就不是C++的了.比如以下代码: #undef INTERFACE #def ...