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 = ;//页数
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的使用的更多相关文章

  1. C# 在Repeater 的ItemDataBound 如何转换e.Item.DataItem 的类型

    1.使用DataSet和DataTable绑定数据源时,用 DataRowView view = (DataRowView)e.Item.DataItem; 2.DataReader绑定数据源时,用 ...

  2. Webform(七)——内置对象(Session、Application)和Repeater的Command操作

    内置对象:用于页面之间的数据交互 为什么要使用这么内置对象?因为HTTP的无状态性. 一.内置对象 (一)Session 跟Cookies一样用来存储用户数据 1.Session.Cookies对比 ...

  3. Webform(五)——内置对象(Response、Request)和Repeater中的数据增删改

    一.内置对象 (一)Response对象 1.简介:response 对象在ASP中负责将信息传递给用户.Response对象用于动态响应客户端请求,并将动态生成的响应结果返回到客户端浏览器中,使用R ...

  4. webform Repeater重复器、地址栏传值、Response

    Repeater: 重复器 <HeaderTemplate></HeaderTemplate> - 头模板:在循环开始时,其内容只会打印一遍 <ItemTemplate& ...

  5. Repeater、地址栏传值、Response--2016年12月30日

    Repeater  Repeater支持以下5种模板       ● ItemTemplate : 对每一个数据项进行格式设置 [Formats each item from the data sou ...

  6. C#中用radio单选Repeater循环数据,js实现

    <asp:Repeater ID="rpt" runat="server"> <ItemTemplate> <tr data-id ...

  7. asp:Repeater实例备忘

    1.前置部分 <asp:Repeater ID="rptPlanNo" runat="server" OnItemDataBound="rptP ...

  8. webform Repeater、地址栏传值、Response

    Repeater: 重复器 Repeater中有五个模板,这里需要注意的是4个 <HeaderTemplate> - 开头,只执行一次的内容 <ItemTemplate> - ...

  9. ASP.NET中获取Repeater模板列中LinkButton按钮事件中获取ID等

    前台页面中: <asp:Repeater ID="repComment" runat="server">            <ItemTe ...

  10. Repeater的分页

      Repeater控件是个好东西.轻量级.又好用.完全的自定义.但是,正是因为这些优点它没有自动分页的功能.这个需要研究一下.我看了一下起点等小说网站,那些什么推荐排名榜用Repeater控件那是很 ...

随机推荐

  1. c++ 预处理指令#define, #endif...

    常见的预处理指令有: # 空指令,无任何效果 # include 包含一个源代码文件 #define 定义宏 #undef 取消已定义的宏 #if 如果给定条件为真,则编译下面代码 #ifdef 如果 ...

  2. IntelliJ IDEA设置maven

    1.更改默认的maven仓库 2.手动更新maven 项目——也就是下载依赖的jar包 3. 不想每次手动更新,设置IDEA自动更新mav项目,下载jar包

  3. BZOJ 5296: [Cqoi2018]破解D-H协议(BSGS)

    传送门 解题思路 \(BSGS\)裸题??要求的是\(g^a =A (mod\) \(p)\),设\(m\)为\(\sqrt p\),那么可以设\(a=i*m-j\),式子变成 \[ g^{i*m-j ...

  4. LOJ 2980 「THUSCH 2017」大魔法师——线段树

    题目:https://loj.ac/problem/2980 线段树维护矩阵. 然后是 30 分.似乎是被卡常了?…… #include<cstdio> #include<cstri ...

  5. The Tree-planting Day and Simple Disjoint Sets

    First I have to say: I have poor English. I am too young, too simple, sometimes naïve. It was tree-p ...

  6. python中实现查找字符串的find函数

    第五题:自己实现一个字符串的find函数1.在一个字符串中查找另一个字符串2.找到了返回第一次出现的位置3.没找到返回-14.参数s1为源字符串,参数s2为要查找的字符串 def index_of_s ...

  7. linux记事工具:RedNotebook Lifeograph Kontact ThotKeeper

    Linux桌面有许多灵活而功能强大的日记工具,如支持标签.加密.多种日志模版和实时搜索.其中的优秀者包括: RedNotebook Lifeograph Kontact ThotKeeper

  8. ceph-cluster map

    知道cluster topology,是因为这5种cluster map. ====================================== 知道cluster topology,是因为这 ...

  9. getAttribute 与getParmeter 区别

    1.getAttribute是取得jsp中 用setAttribute設定的attribute 2.parameter得到的是string:attribute得到的是object 3.request. ...

  10. leetcode-解题记录 771. 宝石与石头

    题目: 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字符 ...