Repeater的使用
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Repeater的使用
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                1.頁(yè)面代碼
如果要分頁(yè),那么頁(yè)面開頭必須寫(<%@ Register Src="~/Controls/Page.ascx" TagName="Page" TagPrefix="uc1" %>)
并且分頁(yè),頁(yè)腳<uc1:Page ID="Page2" runat="server" /> 前面的uc1要跟上面的TagPrefix值一樣
<table class="table" id="gv"><%--頭標(biāo)--%>
<thead>
?? ?<tr>
?? ??? ?<td width="50px" class="auto-style1">
?? ??? ??? ?<asp:LinkButton ID="LinkButton1" runat="server" OnClick="DeleteByChk"? OnClientClick="javascript:return checkValues('您確定要批量刪除數(shù)據(jù)嗎?')">刪除</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">訂單狀態(tài)</td>
?? ??? ?<td width="250px" class="auto-style1">任務(wù)名稱</td>
?? ??? ?<td width="50px" class="auto-style1">銷售編號(hào)</td>
?? ??? ?<td width="50px" class="auto-style1">合同編號(hào)</td>
?? ??? ?<td width="50px" class="auto-style1">客戶名稱</td>
?? ??? ?<td width="50px" class="auto-style1">聯(lián)系人</td>
?? ??? ?<td width="50px" class="auto-style1">聯(lián)系電話</td>
?? ??? ?<td width="50px" class="auto-style1">管理</td>
?? ?</tr>
</thead>
<%--數(shù)據(jù)的綁定--%>
<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="你確定要?jiǎng)h除這一項(xiàng)嗎?" OnClick="Delete" >刪除</asp:LinkButton>
?? ??? ??? ?</td>
?? ??? ?</tr>
?? ?</ItemTemplate>
</asp:Repeater>
</table>
<%--分頁(yè),頁(yè)腳--%>
<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.數(shù)據(jù)的展示
private void show(){DataTable dt = System_Project_TasksBLL.GetList("");//分頁(yè)int pageNumber = 1;//頁(yè)數(shù)int pageSize = 50;//每一頁(yè)顯示數(shù)//判斷是否需要分頁(yè)if (!string.IsNullOrEmpty(Request.QueryString["page"]))pageNumber = Convert.ToInt32(Request.QueryString["page"]);//把datatable類型的數(shù)據(jù)轉(zhuǎn)換為list集合類型的數(shù)據(jù)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);}
//篩選要顯示的數(shù)據(jù)PagedDataSource pageDataSource = new PagedDataSource(){DataSource = list,//數(shù)據(jù)源AllowPaging = true,//是否開啟分頁(yè)PageSize = pageSize,//每一頁(yè)顯示數(shù)CurrentPageIndex = pageNumber,//開始頁(yè)的位置 };//下腳的分頁(yè)菜單的制作,pageNumber:當(dāng)前頁(yè)面的頁(yè)數(shù) pageDataSource.PageCount:獲取數(shù)據(jù)一共有多少頁(yè)this.Page2.sty("meneame", pageNumber, pageDataSource.PageCount, "?page=");//賦值this.num.InnerHtml = string.Concat("當(dāng)前總計(jì) - <span style='color:#ff0000; font-weight:bold;'>",dt.Rows.Count , "</span>條-數(shù)據(jù)");this.rpt.DataSource = pageDataSource;this.rpt.DataBind();}
?
3.對(duì)控件的一些基本操作
protected void Delete(object sender, EventArgs e){//查找此控件的上一個(gè)層級(jí)RepeaterItem parent = (sender as LinkButton).Parent as RepeaterItem;//在此層級(jí)下面查找控件(并不是找此層級(jí)的子集)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("您好!工程測(cè)試單刪除成功!");Response.Redirect(string.Concat("/InfoTip/Operate_Success.aspx?returnpage=", base.Request.Url.AbsoluteUri, "&tip=", str));}}protected void DeleteByChk(object sender, EventArgs e){//遍歷Repeater每一行數(shù)據(jù)foreach (RepeaterItem item in this.rpt.Items){//獲取每一行數(shù)據(jù)中的id叫chk的控件HtmlInputCheckBox htmlInputCheckBox = item.FindControl("chk") as HtmlInputCheckBox;//判斷此行數(shù)據(jù)的checkbox有沒有勾選上if (!htmlInputCheckBox.Checked){//如果沒有,那么跳過(guò)此次循環(huán)continue;}//獲取idint num = Convert.ToInt32(htmlInputCheckBox.Value);//調(diào)用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.頁(yè)面的展示
?
轉(zhuǎn)載于:https://www.cnblogs.com/zjdbk/p/9844429.html
總結(jié)
以上是生活随笔為你收集整理的Repeater的使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: 2018.12.18运算符,分支结构(循
- 下一篇: Linux CentOS 6.5 + A
