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>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<uc1:Page ID="Page2" runat="server" />&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>

2.数据的展示

private void show(){DataTable dt = System_Project_TasksBLL.GetList("");//分页int pageNumber = 1;//页数int pageSize = 50;//每一页显示数//判断是否需要分页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;}//获取idint 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.页面的展示

转载于:https://www.cnblogs.com/zjdbk/p/9844429.html

Repeater的使用相关推荐

  1. Repeater分页代码

    //ASP.NET中的DataList和Repeater提供了简单快速的方法來显示,其间,我们可以使用<ItemTemplate>更是使我们能随心所欲的控制数据的排放样式! //.可惜的是 ...

  2. Datalist控件,Repeater控件如何分页?

    Asp.net提供了三个功能强大的列表控件:DataGrid.DataList和Repeater控件,但其中只有DataGrid控件提供分页功能.相对DataGrid,DataList和Repeate ...

  3. 使用Repeater的Template

    .NET FX提供了一个方法,就是使用Template来在程序运行时对Repeater的显示进行控制. 这里我就不多说了,可以去看MSDN中的相关资料.(嘿嘿,其实我也没搞多少 ).. 其实主要是pr ...

  4. Repeater控件的分页问题

    作者:zhoubin@mail.sdu.edu.cn 以前做ASP的时间不算短,可是做ASP.NET我是个新手.前几天做项目,遇到一个问题,要求比较复杂的数据格式显示,用DataGrid非常难实现,后 ...

  5. 关于何种情况下使用DataGrid、DataList或Repeater的一些讨论

    作者:Scott Mitchell [概述] WEB开发自从有了基于脚本的WEB编程技术(如ASP)以来,经历了一个漫长的过程.通过使用微软的ASP.Net技术,传统的ASP中大量的.单调乏味的.重复 ...

  6. 使用嵌套的Repeater控件显示分级数据

    作者:wincheer  来自:Asp.Net中文专业网 简介 本文描述如何使用嵌套的Repeater 控件来显示分级数据 .当然了,你也可以将这一技术应用到其他的列表绑定控件上去,比如DataGri ...

  7. 改变Repeater控件中按钮颜色

    昨晚有在论坛看到一帖,手上的工作一直忙到现在,Insus.NET现在抽点时间尝试实现它. Insus.NET没有使用数据库作为数据源,而是使用List<T>作为数据源.因此你在这篇博文中学 ...

  8. 取得Repeater内部控件命令名与命令参数

    前台: <table border="0" cellpadding="0" cellspacing="1" class="m ...

  9. 泛型实体类List绑定到repeater

    泛型实体类List<>绑定到repeater 后台代码: private void bindnewslist(){long num = 100L;List<Model.news> ...

  10. Repeater 嵌套 Repeater

    作为一个刚入行的IT小鸟,每天学习,是必须的! 光自学肯定是不够的!由于本人IQ比较低,经常一个小问题都会想不明白. 还好有媳妇儿的帮助,才把这个功能给实现了. 现在就在这里总结下,以示敬意.o(∩_ ...

最新文章

  1. asp.net ajax学习系列功能强大的UpdatePanel控件
  2. CEDD(Color and Edge Directivity Descriptor)算法
  3. 树形控件Tree Control
  4. 【NLP】【七】fasttext源码解析
  5. 手势检测的回调方法中onfling与onscroll的区别
  6. JS键盘事件(非常详细)
  7. 使用 dotnet-outdated 维护项目 nuget 包版本
  8. Struts2教程9:实现自已的拦截器
  9. ps aux 命令分析
  10. python 批量增加文件前缀_用python批量提取视频中的音频文件
  11. [手把手教]discuzX2插件制作教程__最菜鸟级别的入门坎 【二】
  12. Lua的多任务机制——协程(coroutine)
  13. 关于永恒之蓝MS17-010的描述影响范围及修复方案
  14. 独木舟上的旅行java_贪心算法--独木舟上的旅行
  15. 如何让 select的那个请选择不被选中.获取选中的value值和html
  16. wd移动硬盘测试软件,WD西数 MY Passport移动硬盘拆解评测
  17. VMware vCenter Server 8.0U1 发布 - 集中式管理 vSphere 环境
  18. latex审阅版添加行号,遇见公式就缺失行号
  19. PC端安装android模拟器
  20. 北美电影票房Top10-2019年12月20日:《星战9》1.77亿不及预期

热门文章

  1. emui消息推送服务器,别再抱怨,这次或许真的轮到你了,EMUI9.1推送进度再次更新...
  2. Apollo进阶课程 ⑮丨Apollo自动定位技术详解—百度无人车定位技术
  3. 东明县计算机学校,东明县职业中等专业学校2021年招生信息
  4. FileIo 删除类中的private方法
  5. linux 串口 lsr 0xc9,串口发送0x0D后,从串口接收到数据被转换成了0x0A
  6. C语言隐式/显式类型转换 | C++四种强制类型转换、类的隐式转换、explicit
  7. php-protobuf扩展和代码生成工具使用
  8. 帧同步和状态同步(二)案例分析
  9. C++(23)--多态性与虚函数
  10. 无限踩坑系列(6)-mySQL数据库链接错误