实体类:

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. phpcms(1)phpcms V9 MVC模式 与 URL访问解析(转)

    [1]URL访问解析 观察访问网页时的网址,可以得出模块访问方法,如下示例: http://www.abcd.com.cn/phpcms/index.php?m=content&c=index ...

  2. pdo如何防止 sql注入

    我们使用传统的 mysql_connect .mysql_query方法来连接查询数据库时,如果过滤不严,就有SQL注入风险,导致网站被攻击,失去控制.虽然可以用 mysql_real_escape_ ...

  3. php 魔术方法

    PHP5.0后,php面向对象提成更多方法,使得php更加的强大!! 一些在PHP叫魔术方法的函数,在这里介绍一下:其实在一般的应用中,我们都需要用到他们!! 1.__construct() 当实例化 ...

  4. Config IIS server6.0-- HTTP 错误 500.21 - Internal Server Error 解决方案

    HTTP 错误 500.21 - Internal Server Error 解决方案         不久前重新安装了Windows7,在安装了VS2010 开发平台之后,将网站发布到IIS,访问发 ...

  5. 安装 SQL Server 2005 的硬件和软件要求(官方全面)

    SQL Server 2005 安装要求 本主题介绍了安装 SQL Server 205 的硬件和软件要求,以及查看安装文档的说明. 硬件和软件要求(32 位和 64 位) 访问 SQL Server ...

  6. 程序在nor flash中真的可以运行吗?

    程序在nor flash中可以运行,但是是有限制的,它不能像RAM那样随意的写(尽管它可以随意的读).在norflash上,不能运行写存储器的指令,不过排除写的地方是RAM类.实验中的三个文件如下所示 ...

  7. JavaMail 发送邮件

    JavaMail邮件发送 引用maven jar包 <dependency> <groupId>javax.mail</groupId> <artifactI ...

  8. Re-installation failed due to different application signatures./package name has exist

    http://www.cnblogs.com/qianxudetianxia/archive/2011/04/09/2010468.html

  9. Java多线程初学者指南(12):使用Synchronized块同步变量

    我们可以通过synchronized块来同步特定的静态或非静态方法.要想实现这种需求必须为这些特性的方法定义一个类变量,然后将这些方法的代码用synchronized块括起来,并将这个类变量作为参数传 ...

  10. Python零散收集:

    Python零散收集 转义字符 描述 \(在行尾时) 续行符 \\ 反斜杠符号 \’ 单引号 \” 双引号 \a 响铃 \b 退格(Backspace) \e 转义 \000 空 \n 换行 \v 纵 ...