日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Repeater的使用

發(fā)布時間:2023/12/18 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Repeater的使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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('您確定要批量刪除數(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">任務名稱</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">聯(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="你確定要刪除這一項嗎?" 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.數(shù)據(jù)的展示

private void show(){DataTable dt = System_Project_TasksBLL.GetList("");//分頁int pageNumber = 1;//頁數(shù)int pageSize = 50;//每一頁顯示數(shù)//判斷是否需要分頁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,//是否開啟分頁PageSize = pageSize,//每一頁顯示數(shù)CurrentPageIndex = pageNumber,//開始頁的位置 };//下腳的分頁菜單的制作,pageNumber:當前頁面的頁數(shù) pageDataSource.PageCount:獲取數(shù)據(jù)一共有多少頁this.Page2.sty("meneame", pageNumber, pageDataSource.PageCount, "?page=");//賦值this.num.InnerHtml = string.Concat("當前總計 - <span style='color:#ff0000; font-weight:bold;'>",dt.Rows.Count , "</span>條-數(shù)據(jù)");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每一行數(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){//如果沒有,那么跳過此次循環(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.頁面的展示

?

轉(zhuǎn)載于:https://www.cnblogs.com/zjdbk/p/9844429.html

總結(jié)

以上是生活随笔為你收集整理的Repeater的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。