浏览器页面:

代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
* {
margin: 0px;
padding: 0px;
} #header {
position: relative;
width: %;
height: 80px;
background-color: aqua;
} #footer {
position: relative;
width: %;
height: 150px;
background-color: #e0e0e0;
} #items {
position: relative;
width: %;
margin-left: %;
border: 1px solid yellow;
} .item {
position: relative;
float: left;
width: %;
height: 300px;
margin: 10px 0.5%;
background-color: green;
} .item img {
position: relative;
width: %;
/*width: 200px;*/
/*margin:5px 1%;*/
}
.item div {
position:relative;
width:%;
margin:4px %;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="header"></div>
<div id="items">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div class="item">
<img src="<%#Eval("pic") %>" />
<div>品种:<%#Eval("name") %></div>
<div>现价:<%#Eval("nowprice") %></div>
<div>原价:<%#Eval("oldprice") %></div>
<div>简述:<%#Eval("context") %></div>
</div>
</ItemTemplate>
</asp:Repeater>
<div style="clear: both;"></div>
</div>
<div id="footer"></div>
</form>
</body>
</html>

后台代码

重点:(李献策lxc)

在流式布局中,流式div是不占有位置的,所以要用 “<div style="clear:both;"></div>” 撑起位置(李献策lxc)

=======================================================

ItemCommand的用法:

在DataList中生成事件时的激发。

前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
* {
margin: 0px;
padding: 0px;
} #header {
position: relative;
width: %;
height: 80px;
background-color: aqua;
} #footer {
position: relative;
width: %;
height: 150px;
background-color: #e0e0e0;
} #items {
position: relative;
width: %;
margin-left: %;
border: 1px solid yellow;
} .item {
position: relative;
float: left;
width: %;
height: 300px;
margin: 10px 0.5%;
background-color: green;
} .item img {
position: relative;
width: %;
/*width: 200px;*/
/*margin:5px 1%;*/
}
.item div {
position:relative;
width:%;
margin:4px %;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="header"></div>
<div id="items">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div class="item">
<img src="<%#Eval("pic") %>" />
<div>品种:<%#Eval("name") %></div>
<div>现价:<%#Eval("nowprice") %></div>
<div>原价:<%#Eval("oldprice") %></div>
<div>简述:<%#Eval("context") %></div>
<asp:Button ID="Button1" runat="server" CommandName="Update" CommandArgument='<%#Eval("ids") %>' Text="修改" />
<asp:Button ID="Button2" runat="server" CommandName="Delete" CommandArgument='<%#Eval("ids") %>' Text="删除" />
</div>
</ItemTemplate>
</asp:Repeater>
<div style="clear: both;"></div>
</div>
<div id="footer"></div>
</form>
</body>
</html>

前台代码

后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Repeater1.DataSource = new petData().Select();
Repeater1.DataBind();
}
//Repeater 中按钮触发事件
Repeater1.ItemCommand += Repeater1_ItemCommand;
}
//Repeater 中按钮触发事件
void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Update")
{ }
if (e.CommandName == "Delete")
{ bool ok = new petData().Delete(Convert.ToInt32(e.CommandArgument)); Repeater1.DataSource = new petData().Select();
Repeater1.DataBind();
}
} }

后台代码

知识点:

1、后台注册ItemCommand事件(李献策lxc)

2、前台按钮添加属性:CommandName 和 CommandArgument

3、判断按钮返回的值CommandName是什么,进行相应的操作

4、object source - 触发事件的对象  RepeaterCommandEventArgs e - 触发事件的数据

=======================================================

如何不适用Repeater来展示数据?

前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
* {
margin: 0px;
padding: 0px;
} #header {
position: relative;
width: %;
height: 80px;
background-color: aqua;
} #footer {
position: relative;
width: %;
height: 150px;
background-color: #e0e0e0;
} #items {
position: relative;
width: %;
margin-left: %;
border: 1px solid yellow;
} .item {
position: relative;
float: left;
width: %;
height: 300px;
margin: 10px 0.5%;
background-color: green;
} .item img {
position: relative;
width: %;
/*width: 200px;*/
/*margin:5px 1%;*/
}
.item div {
position:relative;
width:%;
margin:4px %;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="header"></div>
<div id="items">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</div>
<div id="footer"></div>
</form>
</body>
</html>

前台代码

后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Literal1.Text = DataBind();
}
}
public string DataBind()
{
List<pet> plist = new petData().Select(); string end = ""; foreach (pet p in plist)
{
if(p.name=="哈士奇")
{
continue;
}
end += "<div class=\"item\">";
end += "<img src=\"" + p.pic + "\" />";
end += "<div>品种:" + p.name + "</div>";
end += "<div>现价:" + p.nowprice + "</div>";
end += "<div>原价:" + p.oldprice + "</div>";
end += "<div>简述:" + p.context + "</div>";
end += "<a href=\"Delete.aspx?ids=" + p.ids + "\">修改</a>";
end += "&nbsp;";
end += "<a href=\"Update.aspx?ids=" + p.ids + "\">删除</a>";
end += "</div>";
}
end += "<div style=\"clear:both;\"></div>";
return end;
} //<div class="item">
//<img src="<%#Eval("pic") %>" />
//<div>品种:<%#Eval("name") %></div>
//<div>现价:<%#Eval("nowprice") %></div>
//<div>原价:<%#Eval("oldprice") %></div>
//<div>简述:<%#Eval("context") %></div>
//<asp:Button ID="Button1" runat="server" CommandName="Update" CommandArgument='<%#Eval("ids") %>' Text="修改" />
//<asp:Button ID="Button2" runat="server" CommandName="Delete" CommandArgument='<%#Eval("ids") %>' Text="删除" />
//</div>
}

后台代码

优势:进行权限验证,如果不满足权限则不会拼接需要展示的代码,即使“审查代码”也不会显示(李献策lxc)

C#-WebForm-Repeater的灵活运用、ItemCommand的用法-增删改查、如何不适用Repeater来展示数据?的更多相关文章

  1. zkCli的使用 常用的节点增删改查命令用法

    zkCli的使用 常用的节点增删改查命令用法 1. 建立会话  命令格式:zkCli.sh -timeout 0 -r -server ip:port ./zkCli.sh -server -time ...

  2. MongoDB --- 02. 基本操作,增删改查,数据类型,比较符,高级用法,pymongo

    一.基本操作 . mongod 启动服务端 2. mongo 启动客户端 3. show databses 查看本地磁盘的数据库 4. use 库名 切换到要使用的数据库 5. db 查看当前使用的数 ...

  3. python 全栈开发,Day124(MongoDB初识,增删改查操作,数据类型,$关键字以及$修改器,"$"的奇妙用法,Array Object 的特殊操作,选取跳过排序,客户端操作)

    一.MongoDB初识 什么是MongoDB MongoDB 是一个基于分布式文件存储的数据库.由 C++ 语言编写.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介 ...

  4. day6 note 字典的增删改查(以及setdefault用法补充)

    今天的内容主要是join的用法和字典的用法,由于已经有前面的列表作为基础,所以还比较简单,不过因为昨天的作业比较难也比较多,所以作业的讲解占用的时间比较长.我需要好好消化一下作业的部分. 思维导图: ...

  5. 2017年12月13日 LinQ用法基本的增删改查

    LinQ是什么? LinQ是语言集成的查询,是用于C#跟Vb的扩展语言 LinQ的用法 新建一个App_Code文件夹,在文件夹下添加一个数据LinQ to SQL类,可以直接直接点击服务器管理器然后 ...

  6. mongoTemplate简单用法(增删改查)

    分页时查找数量: public long countSample(String id) { Query query = new Query(); if (StringUtil.hasText(id)) ...

  7. WebForm增删改查

    最基本的,拼接字符串在Literal里面显示表,IsPostBack,增删改查基本,?传值 Request接收 LinQ to SQL类 在Default主页里面拖入Literal控件再加入一个按钮, ...

  8. mysql 增删改查最基本用法小结

    目录: 1.新建数据库 2.新建数据表 3.查看表结构 4.增删改查 建立一个数据库students 建立一块数据表class1 内容包括: id 主键 自动编号 无符号位 SMALLINT类型 na ...

  9. Webform(Linq增删改查)

    Linq高集成化的数据访问类,它会自动映射数据库结构,将表名完整映射成为类名,将列名完整映射成字段名数据库数据访问,能大大减少代码量.(1)Linq创建添加LINQ to SQL类,类名需与要连接的数 ...

随机推荐

  1. Kafka学习整理五(Consumer配置)

    Property Default Description group.id   用来唯一标识consumer进程所在组的字符串,如果设置同样的group id,表示这些processes都是属于同一个 ...

  2. 集群监控之 —— ipmi操作指南

    http://blog.csdn.net/yunsongice/article/details/5408802 智能平台管理界面(IPMI,Intelligent Platform Managemen ...

  3. Linux TCP拥塞控制算法原理解析

    这里只是简单梳理TCP各版本的控制原理,对于基本的变量定义,可以参考以下链接: TCP基本拥塞控制http://blog.csdn.net/sicofield/article/details/9708 ...

  4. Debian Mount nfs 出错的解决

    系统未安装 nfs 客户端 #aptitude install nfs-common 解决!

  5. Android Service 通知Activity更新界面的方法研究

    Android Service 通知Activity更新界面的方法研究   Android的最重要的组件式service和activity,那么在使用的过程中,我们最常遇到的问题是他们之间的通信问题. ...

  6. 网络爬虫--requests库中两个重要的对象

    当我们使用resquests.get()时,返回的时response的对象,他包含服务器返回的所有信息,也包含请求的request的信息. 首先: response对象的属性有以下几个, r.stat ...

  7. ZSTU4274 约素 2017-03-22 17:11 66人阅读 评论(0) 收藏

    4274: 约素 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 1807  Solved: 467 Description 判断一个正整数n的约数个数 ...

  8. 试题 G: 外卖店优先级 第十届蓝桥杯

    试题 G: 外卖店优先级时间限制: 1.0s 内存限制: 512.0MB 本题总分: 20 分[问题描述]“饱了么”外卖系统中维护着 N 家外卖店,编号 1 ∼ N.每家外卖店都有一个优先级,初始时 ...

  9. 使用Team Explorer Everywhere (TEE) 2015 SDK获取团队项目的签入策略

    TFS的代码签入策略与IDE工具紧密相关,例如Visual Studio中设置的签入策略,只会影响Visual Studio的团队资源管理器:如果需要在Eclipse的TEE中启用签入策略,你还需要在 ...

  10. 常用脚本--SQL Server获取OS日志

    --=================================================== --SQL Server获取OS日志: ), ), ), ) select @start_d ...