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 = 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.頁面的展示
?