浏览器页面:

代码:

<%@ 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. 将Halcon导出的多个dxf文件合并成一个分图层的dxf文件

    Halcon中可以通过concat_obj合并多个XLD,并且可以通过write_contour_xld_dxf再将XLD保存为.dxf文件.但是,保存后的.dxf文件用AutoCAD打开后发现,它们 ...

  2. hra 直线

    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...

  3. win10 跳过max path 260限制

    参考: https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/ 注 ...

  4. jquery怎么根据后台传过来的值动态设置下拉框、单选框选中

    $(function(){ var sex=$("#sex").val(); var marriageStatus=$("#marriageStatus").v ...

  5. java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)

    这个问题是说明你的JDBC数据库连接位置出错了,请仔细检查 private static String url; private static String username; private sta ...

  6. HDU 1060 Leftmost Digit (数学log)

    题意:给定一个数n,让你求出n的n次方的第一位数. 析:一看这个n快到int极限了,很明显不能直接做,要转化一下.由于这是指数,我们可以把指数拿下来. 也就是取对数,设ans = n ^ n,两边取以 ...

  7. 加载 bean*.xml

    入口 ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:bean*.xml"); /** ...

  8. Spring源码解析 - BeanFactory

    BeanFactory是Spring实现依赖注入的核心接口.提供应用的统一配置注册功能,实现业务开发解偶.使用getBean可以代替单例,原型设计模式. 顶重要的BeanFactory里注释写得太好了 ...

  9. 4D(DLG,DRG,DOM,DEM)

    基于“倾斜+LiDAR+车载”的实景三维建模实现:链接 MapGIS数据可不可以做到数据融合 遥感影像

  10. 20169202 2016-2017-2《Windows攻击》

    Windows攻击 实验要求:使用Metaspoit攻击MS08-067,提交正确得到远程Shell的截图,加上自己的学号水印 (1):MS08-067远程溢出漏洞描述 MS08-067漏洞的全称为& ...