浏览器页面:

代码:

<%@ 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. 使用matplotlib画双纵轴坐标

    一.前言 本文主要使用matplotlib,实现双纵轴坐标的图表绘制.笔者python版本为2.7.15. 二.实践及效果 1. 需求 某个有这么一个成绩表,分别是名字,本次成绩以及进步幅度,现在需要 ...

  2. maven项目 实现 spring mybatis 两个框架整合

    1.maven项目 src main java java源文件 resources 配置文件 beans.xml spring配置文件 <?xml version="1.0" ...

  3. ANGULAR 2 BITS: UNIFIED DEPENDENCY INJECTION

    Angular 1.x has two APIs for injecting dependencies into a directive. These APIs are not interchange ...

  4. Docker添加官方加速源(必须)

    在国内使用Docker必须用加速镜像不然的话无论是pull 官方的还是私有的镜像都会WAIT TIME EXCEED 下面给出macos的添加方式,非常简单 macOS 对于使用 macOS 的用户, ...

  5. Oracle学习笔记(七)

    九.高级查询(分组,子查询)查询升级版: 需要用到三张表员工表: desc emp EMPNO 员工号 ENAME 员工姓名 JOB 员工职位 MGR 老板员工号 HIREDATE 员工入职日期 SA ...

  6. span和input同一行布局的时候,高度偏移解决方案

    input标签或收盘标签 添加代码: vertical-align:top;

  7. 二)quartz.properties

    The Properties File Quartz uses a properties file called (kudos on the originality) quartz.propertie ...

  8. 51nod1057—N的阶乘—(大数阶乘)

    1057 N的阶乘  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 输入N求N的阶乘的准确值.   Input 输入N(1 <= N <=  ...

  9. mysql查看数据库性能常用命令

    mysql> show global status; 可以列出MySQL服务器运行各种状态值,另外,查询MySQL服务器配置信息语句: mysql> show variables; 一.慢 ...

  10. freemarker获取变量的范围的问题

    今天做freemarker的时候,想用一下全局的变量.就是在a.ftl 和 b.ftl页面里面,使用a.action里面放入request的变量.a.action的视图页面是a.ftl ,b.ftl是 ...