repeater灵活运用、repeater的commmand用法、如何不用repeater展示数据
实体类:
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展示数据的更多相关文章
- C#-WebForm-Repeater的灵活运用、ItemCommand的用法-增删改查、如何不适用Repeater来展示数据?
浏览器页面: 代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Defau ...
- Repeater控件的详细用法
中隔行(交替项)呈现一次.通过设置 AlternatingItemTemplate 元素的样式属性,可以为其指定不同的外观. FooterTemplate在所有数据绑定行呈现之后呈现一次的元素.典型的 ...
- WebForm 【Repeater】展示数据
在 Webform 数据展示中 界面层 : HTLM 业务逻辑层 :只能用 C# Repeater 重复器 能够用来循环展示数据 具有5种模板 HeaderTemplat ...
- Repeater控件 ---表格展示数据
简介: Repeater控件是Web 服务器控件中的一个容器控件,它使您可以从页的任何可用数据中创建出自定义列表. Repeater 控件不具备内置的呈现功能,这表示用户必须通过创建模板为 Repea ...
- shell编程系列21--文本处理三剑客之awk中数组的用法及模拟生产环境数据统计
shell编程系列21--文本处理三剑客之awk中数组的用法及模拟生产环境数据统计 shell中的数组的用法: shell数组中的下标是从0开始的 array=("Allen" & ...
- repeater单双行颜色不同,gridview repeater DataList 鼠标经过改变背景颜色
1.gridview 双击GridView的OnRowDataBound事件: 在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示: protected void ...
- Dev控件用法 aspxTreeList 无刷新 aspxGridView 数据
主要是利用 ASPxTreeList 点击事件回发服务器进行数据重新绑定 ASPxTreeList: <SettingsBehavior ExpandCollapseAction="N ...
- SQL学习之Insert的特殊用法(插入检索出的数据,表之间的数据复制)
1.插入检索出的数据 select * from dbo.Customers_1
- Fiddler高级用法-抓取手机app数据包
在上一篇中介绍了Fiddler的基本使用方法.通过上一篇的操作我们可以直接抓取浏览器的数据包.但在APP测试中,我们需要抓取手机APP上的数据包,应该怎么操作呢? Andriod配置方法 1)确保手机 ...
随机推荐
- windows server 2008 R2 忘记administrator密码
第一步: 插入安装光盘,重光驱启动系统,在选择“安装语言”的地方,按shift+F10 在弹出的CMD窗口中,输入以下地址: x:\>c: c:\>cd windows\system32 ...
- 补充一下我对 POJ 3273 的理解,这肯定是我一生写的最多的题解。。。
题目:http://poj.org/problem?id=3273 当分成的组数越多,所有组的最大值就会越小或不变,这一点不难证明: 如果当前分成了group组,最大值是max,那么max的这一 ...
- Spring-boot 配置Aop获取controller里的request中的参数以及其返回值
首先在你的Maven的pom文件里加入aop的依赖: <dependency> <groupId>org.springframework.boot</groupId> ...
- IronPython 源码剖析系列(2):IronPython 引擎的运作流程
http://blog.csdn.net/inelm/article/details/4612987 一.入口点 Python 程序的执行是从 hosting 程序 ipy.exe 开始的,而他的入口 ...
- Android事件分发详解(三)——ViewGroup的dispatchTouchEvent()源码学习
package cc.aa; import android.os.Environment; import android.view.MotionEvent; import android.view.V ...
- java提高篇(十)-----详解匿名内部类 ,形参为什么要用final
在java提高篇-----详解内部类中对匿名内部类做了一个简单的介绍,但是内部类还存在很多其他细节问题,所以就衍生出这篇博客.在这篇博客中你可以了解到匿名内部类的使用.匿名内部类要注意的事项.如何初始 ...
- bzoj1558
好题,初看以为只要差分然后维护相同的段数目但是请注意下面的情况2 3 5 8 9 1 2 3 4 这显然答案是3而不是4因此我们还要再维护ld,rd表示左右单独的段长度和s表示不包括左右单独的段,中间 ...
- poj1286
等价类计数问题,我们就先构造置换群 显然置换分为两种类型,旋转和翻折 先考虑旋转,每旋转i格子,这个置换的循环数为gcd(i,n); (1<=i<=n) 为什么是这个范围,下篇报告再说 翻 ...
- WordPress Platinum SEO插件跨站脚本漏洞
漏洞名称: WordPress Platinum SEO插件跨站脚本漏洞 CNNVD编号: CNNVD-201309-398 发布时间: 2013-09-24 更新时间: 2013-09-24 危害等 ...
- 【转】在Ubuntu上下载、编译和安装Android最新源代码
原文网址:http://blog.csdn.net/luoshengyang/article/details/6559955 看完了前面说的几本书之后,对Linux Kernel和Android有一定 ...