Repeater的使用
1.页面代码
如果要分页,那么页面开头必须写(<%@ Register Src="~/Controls/Page.ascx" TagName="Page" TagPrefix="uc1" %>)
并且分页,页脚<uc1:Page ID="Page2" runat="server" /> 前面的uc1要跟上面的TagPrefix值一样
<table class="table" id="gv">
<%--头标--%>
<thead>
<tr>
<td width="50px" class="auto-style1">
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="DeleteByChk" OnClientClick="javascript:return checkValues('您确定要批量删除数据吗?')">删除</asp:LinkButton>
<input type="checkbox" name="ckb" class="checkall"/>
</td>
<td width="50px" class="auto-style1"><span style="margin-left:20px;">序</span></td>
<td width="100px" class="auto-style1">制单日期</td>
<td width="50px" class="auto-style1">订单状态</td>
<td width="250px" class="auto-style1">任务名称</td>
<td width="50px" class="auto-style1">销售编号</td>
<td width="50px" class="auto-style1">合同编号</td>
<td width="50px" class="auto-style1">客户名称</td>
<td width="50px" class="auto-style1">联系人</td>
<td width="50px" class="auto-style1">联系电话</td>
<td width="50px" class="auto-style1">管理</td>
</tr>
</thead>
<%--数据的绑定--%>
<asp:Repeater runat="server" ID="rpt">
<ItemTemplate>
<tr>
<td><input runat="server" id="chk" type="checkbox" value='<%#Eval("SId")%>' class="checkdelete"/></td>
<td><span style="margin-left:20px;"><%# Container.ItemIndex+1 %></span></td>
<td><span style="margin-left:25px;"><%#Eval("SOperDate")%></span></td>
<td><span style="margin-left:25px;"><%#Eval("SIsLock")%></span></td>
<td><span style="margin-left:25px;"><%#Eval("SName")%></span></td>
<td><span style="margin-left:25px;"><%#Eval("SCode")%></span></td>
<td><span style="margin-left:25px;"><%#Eval("SConNo")%></span></td>
<td><span style="margin-left:25px;"><%#Eval("SComId")%></span></td>
<td><span style="margin-left:25px;"><%#Eval("SLinkMan")%></span></td>
<td><span style="margin-left:25px;"><%#Eval("STell")%></span></td>
<td class="manage">
<a href="TaskInterManage.aspx?SId=<%#Eval("SId") %>" class="show">编辑</a>
<asp:LinkButton runat="server" ID="lb_del" class="delete" title="你确定要删除这一项吗?" OnClick="Delete" >删除</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<%--分页,页脚--%>
<table class="table">
<tr>
<td class="page">
<span style="float:left;" id="num" runat="server"></span>
<uc1:Page ID="Page2" runat="server" /> </td>
</tr>
</table>
2.数据的展示
private void show()
{
DataTable dt = System_Project_TasksBLL.GetList("");
//分页
int pageNumber = ;//页数
int pageSize = ;//每一页显示数 //判断是否需要分页
if (!string.IsNullOrEmpty(Request.QueryString["page"]))
pageNumber = Convert.ToInt32(Request.QueryString["page"]);
//把datatable类型的数据转换为list集合类型的数据
List<System_Project_Tasks> list = new List<System_Project_Tasks>();
foreach (DataRow item in dt.Rows)
{
System_Project_Tasks data = new System_Project_Tasks();
data.SId = Convert.ToInt32(item["SId"].ToString());
data.SOperDate = Convert.ToDateTime(item["SOperDate"].ToString());
data.SIsLock = int.Parse(item["SIsLock"].ToString());
data.SName = item["SName"].ToString();
data.SCode = item["SCode"].ToString();
data.SConNo = item["SConNo"].ToString();
data.SComId = item["SComId"].ToString();
data.SLinkMan = item["SLinkMan"].ToString();
data.STell = item["STell"].ToString();
list.Add(data);
}
//筛选要显示的数据
PagedDataSource pageDataSource = new PagedDataSource()
{
DataSource = list,//数据源
AllowPaging = true,//是否开启分页
PageSize = pageSize,//每一页显示数
CurrentPageIndex = pageNumber,//开始页的位置
};
//下脚的分页菜单的制作,pageNumber:当前页面的页数 pageDataSource.PageCount:获取数据一共有多少页
this.Page2.sty("meneame", pageNumber, pageDataSource.PageCount, "?page=");
//赋值
this.num.InnerHtml = string.Concat("当前总计 - <span style='color:#ff0000; font-weight:bold;'>",dt.Rows.Count , "</span>条-数据");
this.rpt.DataSource = pageDataSource;
this.rpt.DataBind();
}
3.对控件的一些基本操作
protected void Delete(object sender, EventArgs e)
{
//查找此控件的上一个层级
RepeaterItem parent = (sender as LinkButton).Parent as RepeaterItem;
//在此层级下面查找控件(并不是找此层级的子集)
HtmlInputCheckBox htmlInputCheckBox = parent.FindControl("chk") as HtmlInputCheckBox;
//获取chekbox的value值(id)
int num = Convert.ToInt32(htmlInputCheckBox.Value);
//删除
if (bll.Delete(num))
{
string str = HttpContext.Current.Server.HtmlEncode("您好!工程测试单删除成功!");
Response.Redirect(string.Concat("/InfoTip/Operate_Success.aspx?returnpage=", base.Request.Url.AbsoluteUri, "&tip=", str));
}
} protected void DeleteByChk(object sender, EventArgs e)
{
//遍历Repeater每一行数据
foreach (RepeaterItem item in this.rpt.Items)
{
//获取每一行数据中的id叫chk的控件
HtmlInputCheckBox htmlInputCheckBox = item.FindControl("chk") as HtmlInputCheckBox;
//判断此行数据的checkbox有没有勾选上
if (!htmlInputCheckBox.Checked)
{
//如果没有,那么跳过此次循环
continue;
}
//获取id
int num = Convert.ToInt32(htmlInputCheckBox.Value);
//调用bll层方法删除
bll.Delete(num);
}
string str = HttpContext.Current.Server.HtmlEncode("您好!邮件已彻底删除!");
base.Response.Redirect(string.Concat("/InfoTip/Operate_Success.aspx?returnpage=", base.Request.Url.AbsoluteUri, "&tip=", str));
}
4.页面的展示
Repeater的使用的更多相关文章
- C# 在Repeater 的ItemDataBound 如何转换e.Item.DataItem 的类型
1.使用DataSet和DataTable绑定数据源时,用 DataRowView view = (DataRowView)e.Item.DataItem; 2.DataReader绑定数据源时,用 ...
- Webform(七)——内置对象(Session、Application)和Repeater的Command操作
内置对象:用于页面之间的数据交互 为什么要使用这么内置对象?因为HTTP的无状态性. 一.内置对象 (一)Session 跟Cookies一样用来存储用户数据 1.Session.Cookies对比 ...
- Webform(五)——内置对象(Response、Request)和Repeater中的数据增删改
一.内置对象 (一)Response对象 1.简介:response 对象在ASP中负责将信息传递给用户.Response对象用于动态响应客户端请求,并将动态生成的响应结果返回到客户端浏览器中,使用R ...
- webform Repeater重复器、地址栏传值、Response
Repeater: 重复器 <HeaderTemplate></HeaderTemplate> - 头模板:在循环开始时,其内容只会打印一遍 <ItemTemplate& ...
- Repeater、地址栏传值、Response--2016年12月30日
Repeater Repeater支持以下5种模板 ● ItemTemplate : 对每一个数据项进行格式设置 [Formats each item from the data sou ...
- C#中用radio单选Repeater循环数据,js实现
<asp:Repeater ID="rpt" runat="server"> <ItemTemplate> <tr data-id ...
- asp:Repeater实例备忘
1.前置部分 <asp:Repeater ID="rptPlanNo" runat="server" OnItemDataBound="rptP ...
- webform Repeater、地址栏传值、Response
Repeater: 重复器 Repeater中有五个模板,这里需要注意的是4个 <HeaderTemplate> - 开头,只执行一次的内容 <ItemTemplate> - ...
- ASP.NET中获取Repeater模板列中LinkButton按钮事件中获取ID等
前台页面中: <asp:Repeater ID="repComment" runat="server"> <ItemTe ...
- Repeater的分页
Repeater控件是个好东西.轻量级.又好用.完全的自定义.但是,正是因为这些优点它没有自动分页的功能.这个需要研究一下.我看了一下起点等小说网站,那些什么推荐排名榜用Repeater控件那是很 ...
随机推荐
- 服务器构建CentOS+Jenkins+Git+Maven之爬坑
ssh端口变更后,git如何访问远端中央代码库 参考来源: http://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin http://blog.csdn ...
- spring-boot整合Mybatis多数据源案例
1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 4.0.0 2.GITHUB地址 https://github.com/nbfujx/springBo ...
- PHP curl_errno函数
curl_errno — 返回最后一次的错误号 说明 int curl_errno ( resource $ch ) 返回最后一次cURL操作的错误号. 参数 ch 由 curl_init() 返回的 ...
- 【bzoj1458】士兵占领(最大流||有源汇最大流)
转载 http://hzwer.com/2963.html Description 有一个M * N的棋盘,有的格子是障碍.现在你要选择一些格子来放置一些士兵,一个格子里最多可以放置一个士兵,障碍格里 ...
- E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarly unavailable)
1. 问题详细提示如下: E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarly unava ...
- hdu 5181 numbers——思路+区间DP
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5181 题解:https://www.cnblogs.com/Miracevin/p/10960717.ht ...
- BUUCTF | MD5
题目:e00cf25ad42683b3df678c61f42c6bda flag{admin1} 算是一个资源收集吧,Orz,https://www.cmd5.com/
- JS基础入门篇(六)— 数据类型
1.数据类型 数据类型:我感觉就是对数据的种类进行分类.就好比把人分为儿童,青少年,中年,老年一样. 基础数据类型: Number(数字),String(字符串),Null(空),Undefined( ...
- python中的单例模式及其实现
单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在. 当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场. 比如, ...
- (转)超详细java中的ClassLoader详解
转:https://blog.csdn.net/briblue/article/details/54973413 ClassLoader翻译过来就是类加载器,普通的java开发者其实用到的不多,但对于 ...