实体类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; /// <summary>
/// gouwu 的摘要说明
/// </summary>
public class gouwu
{
public gouwu()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public int ids { get; set; }
public string pic { get; set; }
public string name { get; set; }
public decimal nowprice { get; set; }
public decimal oldprice { get; set; }
public string context { get; set; } }

数据访问类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
/// <summary>
/// gouwudata 的摘要说明
/// </summary>
public class gouwudata
{
SqlConnection conn = null;
SqlCommand cmd = null;
public gouwudata()
{
conn = new SqlConnection("server=.;database=data0928;user=sa;pwd=123");
cmd = conn.CreateCommand();
}
public List<gouwu> select()
{
List<gouwu> glist = new List<gouwu>();
cmd.CommandText = "select*from gouwu";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
gouwu g = new gouwu();
g.ids = Convert.ToInt32(dr[]);
g.pic = dr[].ToString();
g.name = dr[].ToString();
g.nowprice = Convert.ToDecimal(dr[]);
g.oldprice = Convert.ToDecimal(dr[]);
g.context = dr[].ToString(); glist.Add(g);
} } conn.Close();
return glist;
}
public void delete(int ids)
{
cmd.CommandText = "delete from gouwu where ids='"+ids+"'";
conn.Open();
cmd.ExecuteNonQuery();
conn.Close(); }
}

aspx里:

<%@ 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>
* {
padding:0px;
margin:0px;
} #header {
width:%;
height:80px;
background-color:navy;
position:relative;
}
#footer {
width:%;
height:80px;
background-color:black;
position:relative;
}
#items {
width:%;
margin-left:%;
position:relative; }
.item {
position:relative;
width:23.5%;
margin-left:0.5%;
margin-right:0.5%;
height:295px;
margin-top:5px;
border:solid 1px;
float:left;
margin-bottom:5px;
}
.item img {
position:relative;
width:%;
height:%;
}
.itemname {
position:relative;
width:%;
margin-left:%;
font-size:18px;
}
.itemprice {
position:relative;
width:%;
color:red;
text-align:right;
font-size:18px;
}
.itemprice span {
font-size:12px;
text-decoration:line-through;
}
.itemcon {
position:relative;
width:%;
margin-left:%;
} </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 class="itemname"><%#Eval("name") %></div>
<div class="itemprice">价格:<%#Eval("nowprice") %><span><%#Eval("oldprice") %></span></div>
<div class="itemcon"><%#Eval("context") %></div>
<asp:Button ID="Button1" runat="server" Text="删除" CommandName="delete" CommandArgument='<%#Eval("ids") %>' /><%--repeater的command方法--%>
</div> </ItemTemplate> </asp:Repeater>
<div style="clear:both"></div>//使高度自适应
</div>
<div id="footer"></div> </form>
</body>
</html>

cs里:

Repeater的Command操作

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

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

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

后台调用:e.CommandName

3、CommandArgument : 触发事件所传递过来的数据,放在这里面 界面值绑定时要用  单引号 !!!!!! 不同的name可以有不同的commandarguement值,在判断对应name时,可以取到对应的Arguement值  if (e.CommandName == "delete")

后台调用:e.CommandArgument 

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 gouwudata().select();
Repeater1.DataBind();
}
Repeater1.ItemCommand += Repeater1_ItemCommand; } void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "delete")//repeater的command方法
{
new gouwudata().delete(Convert.ToInt32(e.CommandArgument));//repeater的command方法
Repeater1.DataSource = new gouwudata().select();//删除后及时刷新数据
Repeater1.DataBind();
}
}
}

如何不用repeater展示数据:

aspx中:用literal

<body style="font-family: 微软雅黑;">
<form id="form1" runat="server">
<div id="header">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
<div id="items"> <asp:Literal ID="Literal1" runat="server"></asp:Literal> <div style="clear: both;"></div>
</div> <div id="footer"></div>
</form>
</body>

cs中:

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()
{
string end = ""; List<gouwu> glist = new gouwuData().Select(); foreach (gouwu g in glist)
{
if (g.name == "猕猴桃")
{
continue;
} end += "<div class=\"item\">";
end += "<img src=\"" + g.pic + "\" />";
end += " <div class=\"item-name\">" + g.name + "</div>";
end += "<div class=\"item-price\">价格:" + g.nowPrice + "<span>" + g.oldPrice + "</span></div>";
end += "<div class=\"item-context\">" + g.context + "</div>";
end += "<a href=\"Delete.aspx?id=" + g.ids + "\">删除</a>";
end += "</div>";
}
return end;
} }

repeater灵活运用、repeater的commmand用法、如何不用repeater展示数据的更多相关文章

  1. C#-WebForm-Repeater的灵活运用、ItemCommand的用法-增删改查、如何不适用Repeater来展示数据?

    浏览器页面: 代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Defau ...

  2. Repeater控件的详细用法

    中隔行(交替项)呈现一次.通过设置 AlternatingItemTemplate 元素的样式属性,可以为其指定不同的外观. FooterTemplate在所有数据绑定行呈现之后呈现一次的元素.典型的 ...

  3. WebForm 【Repeater】展示数据

       在 Webform 数据展示中      界面层  : HTLM 业务逻辑层 :只能用 C#  Repeater    重复器  能够用来循环展示数据 具有5种模板  HeaderTemplat ...

  4. Repeater控件 ---表格展示数据

    简介: Repeater控件是Web 服务器控件中的一个容器控件,它使您可以从页的任何可用数据中创建出自定义列表. Repeater 控件不具备内置的呈现功能,这表示用户必须通过创建模板为 Repea ...

  5. shell编程系列21--文本处理三剑客之awk中数组的用法及模拟生产环境数据统计

    shell编程系列21--文本处理三剑客之awk中数组的用法及模拟生产环境数据统计 shell中的数组的用法: shell数组中的下标是从0开始的 array=("Allen" & ...

  6. repeater单双行颜色不同,gridview repeater DataList 鼠标经过改变背景颜色

    1.gridview 双击GridView的OnRowDataBound事件: 在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示: protected void  ...

  7. Dev控件用法 aspxTreeList 无刷新 aspxGridView 数据

    主要是利用 ASPxTreeList 点击事件回发服务器进行数据重新绑定 ASPxTreeList: <SettingsBehavior ExpandCollapseAction="N ...

  8. SQL学习之Insert的特殊用法(插入检索出的数据,表之间的数据复制)

    1.插入检索出的数据 select * from dbo.Customers_1

  9. Fiddler高级用法-抓取手机app数据包

    在上一篇中介绍了Fiddler的基本使用方法.通过上一篇的操作我们可以直接抓取浏览器的数据包.但在APP测试中,我们需要抓取手机APP上的数据包,应该怎么操作呢? Andriod配置方法 1)确保手机 ...

随机推荐

  1. mongodb3.2系统性学习——2、write concern mongodb 写安全机制

    为了尊重作者原文章位置:http://kyfxbl.iteye.com/blog/1952941 首先讲一下mongodb 的写操作过程: mongodb有一个write concern的设置,作用是 ...

  2. php tpl 模板页面如和给js文件传参数

    有一个参数,服务器传给了php 模板页面,但模板包含的js需要得到这个参数值.如何处理: 一,在引入页面前加一句代码 <script type="text/javascript&quo ...

  3. shell编程的一些例子5

    1.here文档 here文档允许我们调用一个交互式程序:可以从脚本程序中输出大量的文本,从而不必echo每行 例子1: #!/bin/bash cat<<!DATA! This is a ...

  4. 懒加载 jquery代码

    懒加载代码.据说这是jquery代码. 说白了就是在 开始的时候调用,这个和C#代码错误处理机制是一样的. function check() {          var obj = document ...

  5. SVN - 配置

    版本控制器 1.创建文件夹 svn 2.打开终端 进入该文件夹 3.输入 svnadmin 如果有错 xcrun: error: active developer path ("/Appli ...

  6. android SurfaceView绘制 重新学习--切图clipRect详解

    解释都在代码注释中: public class SampleView extends View { private Paint mPaint; private Path mPath; public S ...

  7. 个人笔记--struts2对Action的权限拦截

    一.编写一个类实现com.opensymphony.xwork2.interceptor.Interceptor 接口 PermissionInterceptor.java <pre name= ...

  8. js 模块化

    http://kb.cnblogs.com/page/132461/ http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth. ...

  9. Android LogCat 日志记录

    日志级别列表如下(从低到高): V — Verbose (lowest priority) D — Debug I — Info W — Warning E — Error F — Fatal S — ...

  10. flume 报File Channel transaction capacity cannot be greater than the capacity of the channel capacity错误

    今天在部署flume集群时,在启动collector服务器没报错,启动agent服务器报错: File Channel transaction capacity cannot be greater t ...