repeater控件自定义Url分页带参数
Posted 将哥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了repeater控件自定义Url分页带参数相关的知识,希望对你有一定的参考价值。
repeater控件的效果图如下:
该页面实现的功能如下:
1.上下分页,(也可以带首页和末页,我只是禁掉了没用)
2.根据用户输入的指定分页索引进行跳转
3.根据筛选数据的参数进行URL分页的参数传递
4.数据的导出功能
前台代码:
<!--表格具体内容--> <div class="table-box"> <table> <thead> <tr> <th>编号</th> <th>姓名</th> <th>性别</th> <th>出生年月</th> <th>供应商</th> <th>面试企业</th> <th>面试日期</th> <th>当天费用</th> <th>操作栏</th> </tr> </thead> <tbody> <asp:Repeater ID="Repeater_PersonnelRosterList" OnItemDataBound="Repeater_PersonnelRosterList_ItemDataBound" OnItemCommand="Repeater_PersonnelRosterList_ItemCommand" runat="server"> <ItemTemplate> <tr style=\'background-color: <%#(Container.ItemIndex%2==0)?"#fff":"#eff6fa"%>\'> <td><%# Eval("Id") %></td> <td><%# Eval("Name") %></td> <td><%# Eval("Sex") %></td> <td><%# Eval("BrothDate") %></td> <td><%# Eval("GongYingShangName") %></td> <td><%# Eval("EnterpriseName") %></td> <td> <%# DateTime.Parse( Eval("MianShiDate").ToString()).ToShortDateString() %> </td> <td><%# Eval("TodayFeiYong") %></td> <td> <asp:HyperLink ID="BtnEditPersonnel" Visible="false" ToolTip="编辑详情、价格调整" runat="server"><img src="../images/ico/file_edit.gif" style="float:left;margin:8px;" /></asp:HyperLink> <asp:LinkButton ID="BtnDeletePersonnel" Visible="false" runat="server" CommandName="DeletePersonnel" CommandArgument=\'<%# Eval("Id") %>\' ToolTip="删除" ><img src="../images/ico/trash.gif" style="float:left;margin:8px;" /></asp:LinkButton> </td> </tr> </ItemTemplate> </asp:Repeater> </tbody> </table> </div> </div><!--表格结束--> <div class="announcement_splitpage"> <div class="table_splitpage_div2"> <asp:LinkButton ID="LinkBtnToPage" OnClick="LinkBtnToPage_Click" CssClass="gotoPagebtn" runat="server"><div class="fenyebtn2">跳转</div></asp:LinkButton> <span> <asp:TextBox ID="txtPageIndex" CssClass="toPageIndex" runat="server"></asp:TextBox> </span> <asp:HyperLink ID="lnkNext" runat="server"><div class="fenyebtn"><img src="../images/ico/arrow_large_right.png" /></div></asp:HyperLink> <span class="splitpagecount"><asp:Label ID="lbCountPage" runat="server" Text=""></asp:Label></span> <span class="splitpagecount">/</span> <span class="splitpagecount"><asp:Label ID="lbCurentPage" runat="server" Text=""></asp:Label></span> <asp:HyperLink ID="lnkTop" runat="server"><div class="fenyebtn"><img src="../images/ico/arrow_large_left.png" /></div></asp:HyperLink> <span class="splitpagecount">条数据</span> <span class="splitpagecount"><asp:Label ID="lbDataCount" runat="server" Text=""></asp:Label></span> <span class="splitpagecount">共计</span> </div> </div>
后台代码:
PagedDataSource pds = new PagedDataSource(); private int PageSize = 8;//定义分页每页初始大小 StringBuilder sbUrl = new StringBuilder(); protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Request.QueryString["gongyingshangName"] != null && Request.QueryString["startDate"] != null && Request.QueryString["endDate"] != null) { this.txt_gongyingshangName.Value = Request.QueryString["gongyingshangName"].ToString(); this.txtMiana.Value = Request.QueryString["startDate"].ToString(); this.txtMianb.Value = Request.QueryString["endDate"].ToString(); } else if (Request.QueryString["enterName"] != null && Request.QueryString["startDate"] != null && Request.QueryString["endDate"] != null) { this.txt_enterName.Value = Request.QueryString["enterName"].ToString(); this.txtMiana.Value = Request.QueryString["startDate"].ToString(); this.txtMianb.Value = Request.QueryString["endDate"].ToString(); } else if (Request.QueryString["employeName"] != null && Request.QueryString["startDate"] != null && Request.QueryString["endDate"] != null) { this.txtName.Value = Request.QueryString["employeName"].ToString(); this.txtMiana.Value = Request.QueryString["startDate"].ToString(); this.txtMianb.Value = Request.QueryString["endDate"].ToString(); } else if (Request.QueryString["startDate"] != null && Request.QueryString["endDate"] != null) { this.txtMiana.Value = Request.QueryString["startDate"].ToString(); this.txtMianb.Value = Request.QueryString["endDate"].ToString(); } BindPersonnelRosterList(); this.DataBind(); } } private void BindPersonnelRosterList() { LuYongRosterService lrs = new LuYongRosterService(); List<LuYongMingDanInfo> lymdlist = new List<LuYongMingDanInfo>(); if (this.txt_gongyingshangName.Value.ToString() != "供应商姓名") { if (String.IsNullOrWhiteSpace(this.txtMiana.Value.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'请选择面试开始日期!\');", true); this.txtMiana.Focus(); return; } if (String.IsNullOrWhiteSpace(this.txtMianb.Value.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'请选择面试结束日期!\');", true); this.txtMianb.Focus(); return; } if (DateTime.Parse(this.txtMiana.Value.ToString()) > DateTime.Parse(this.txtMianb.Value.ToString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试开始日期不能大于面试结束日期!\');", true); this.txtMiana.Focus(); return; } if (DateTime.Parse(this.txtMiana.Value.ToString()) > DateTime.Parse(System.DateTime.Now.ToShortDateString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试开始日期不能大于当天日期!\');", true); this.txtMiana.Focus(); return; } if (DateTime.Parse(this.txtMianb.Value.ToString()) > DateTime.Parse(System.DateTime.Now.ToShortDateString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试结束日期不能大于当天日期!\');", true); this.txtMianb.Focus(); return; } sbUrl.Clear(); sbUrl.Append("&gongyingshangName=" + this.txt_gongyingshangName.Value.ToString().Trim()); sbUrl.Append("&startDate=" + this.txtMiana.Value.ToString().Trim()); sbUrl.Append("&endDate=" + this.txtMianb.Value.ToString().Trim()); lymdlist = lrs.GetAllLuYongRosterListByKeys(this.txt_gongyingshangName.Value.ToString().Trim(), null, null, this.txtMiana.Value.ToString().Trim(), this.txtMianb.Value.ToString().Trim()); } else if (this.txt_enterName.Value.ToString() != "企业名称") { if (String.IsNullOrWhiteSpace(this.txtMiana.Value.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'请选择面试开始日期!\');", true); this.txtMiana.Focus(); return; } if (String.IsNullOrWhiteSpace(this.txtMianb.Value.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'请选择面试结束日期!\');", true); this.txtMianb.Focus(); return; } if (DateTime.Parse(this.txtMiana.Value.ToString()) > DateTime.Parse(this.txtMianb.Value.ToString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试开始日期不能大于面试结束日期!\');", true); this.txtMiana.Focus(); return; } if (DateTime.Parse(this.txtMiana.Value.ToString()) > DateTime.Parse(System.DateTime.Now.ToShortDateString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试开始日期不能大于当天日期!\');", true); this.txtMiana.Focus(); return; } if (DateTime.Parse(this.txtMianb.Value.ToString()) > DateTime.Parse(System.DateTime.Now.ToShortDateString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试结束日期不能大于当天日期!\');", true); this.txtMianb.Focus(); return; } sbUrl.Clear(); sbUrl.Append("&enterName=" + this.txt_enterName.Value.ToString().Trim()); sbUrl.Append("&startDate=" + this.txtMiana.Value.ToString().Trim()); sbUrl.Append("&endDate=" + this.txtMianb.Value.ToString().Trim()); lymdlist = lrs.GetAllLuYongRosterListByKeys(null, this.txt_enterName.Value.ToString().Trim(), null, this.txtMiana.Value.ToString().Trim(), this.txtMianb.Value.ToString().Trim()); } else if (this.txtName.Value.ToString() != "员工姓名") { if (String.IsNullOrWhiteSpace(this.txtMiana.Value.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'请选择面试开始日期!\');", true); this.txtMiana.Focus(); return; } if (String.IsNullOrWhiteSpace(this.txtMianb.Value.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'请选择面试结束日期!\');", true); this.txtMianb.Focus(); return; } if (DateTime.Parse(this.txtMiana.Value.ToString()) > DateTime.Parse(this.txtMianb.Value.ToString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试开始日期不能大于面试结束日期!\');", true); this.txtMiana.Focus(); return; } if (DateTime.Parse(this.txtMiana.Value.ToString()) > DateTime.Parse(System.DateTime.Now.ToShortDateString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试开始日期不能大于当天日期!\');", true); this.txtMiana.Focus(); return; } if (DateTime.Parse(this.txtMianb.Value.ToString()) > DateTime.Parse(System.DateTime.Now.ToShortDateString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试结束日期不能大于当天日期!\');", true); this.txtMianb.Focus(); return; } sbUrl.Clear(); sbUrl.Append("&employeName=" + this.txtName.Value.ToString().Trim()); sbUrl.Append("&startDate=" + this.txtMiana.Value.ToString().Trim()); sbUrl.Append("&endDate=" + this.txtMianb.Value.ToString().Trim()); lymdlist = lrs.GetAllLuYongRosterListByKeys(null, null,this.txtName.Value.ToString().Trim(), this.txtMiana.Value.ToString().Trim(), this.txtMianb.Value.ToString().Trim()); } else if (!String.IsNullOrWhiteSpace(this.txtMiana.Value.ToString().Trim())) { if (String.IsNullOrWhiteSpace(this.txtMianb.Value.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'请选择面试结束日期!\');", true); this.txtMianb.Focus(); return; } if (DateTime.Parse(this.txtMiana.Value.ToString()) > DateTime.Parse(this.txtMianb.Value.ToString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试开始日期不能大于面试结束日期!\');", true); this.txtMiana.Focus(); return; } if (DateTime.Parse(this.txtMiana.Value.ToString()) > DateTime.Parse(System.DateTime.Now.ToShortDateString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试开始日期不能大于当天日期!\');", true); this.txtMiana.Focus(); return; } if (DateTime.Parse(this.txtMianb.Value.ToString()) > DateTime.Parse(System.DateTime.Now.ToShortDateString())) { ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert(\'面试结束日期不能大于当天日期!\');", true); this.txtMianb.Focus(); return; } sbUrl.Clear(); sbUrl.Append("&startDate=" + this.txtMiana.Value.ToString().Trim()); sbUrl.Append("&endDate=" + this.txtMianb.Value.ToString().Trim()); lymdlist = lrs.GetAllLuYongRosterListByKeys(null, null, null, this.txtMiana.Value.ToString().Trim(), this.txtMianb.Value.ToString().Trim()); } else { lymdlist = lrs.GetAllLuYongRosterList(); } pds.DataSource = lymdlist; pds.AllowPaging = true; pds.PageSize = PageSize; int CurrentPage; if (!String.IsNullOrWhiteSpace(this.txtPageIndex.Text.ToString().Trim())) { if (Helper.IsNum(this.txtPageIndex.Text.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert(\'页码数只能输入数字!\')", true); this.txtPageIndex.Focus(); this.txtPageIndex.Text = this.lbCurentPage.Text.ToString(); return; } else if (int.Parse(this.txtPageIndex.Text.ToString().Trim()) > int.Parse(this.lbCountPage.Text.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert(\'所输页数不能大于总页数!\')", true); this.txtPageIndex.Focus(); this.txtPageIndex.Text = this.lbCountPage.Text.ToString(); return; } else { CurrentPage = Convert.ToInt32(this.txtPageIndex.Text.ToString().Trim()); } } else if (Request.QueryString["Page"] != null) { CurrentPage = Convert.ToInt32(Request.QueryString["Page"]); } else { CurrentPage = 1; } pds.CurrentPageIndex = CurrentPage - 1;//当前页的索引就等于当前页码-1; if (!pds.IsFirstPage) { //Request.CurrentExecutionFilePath 为当前请求的虚拟路径 this.lnkTop.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - 1) + sbUrl; //this.lnkFist.Enabled = this.lnkTop.Enabled = true; //this.lnkNext.Enabled = this.lnkLast.Enabled = true; } else { //this.lnkFist.Enabled = this.lnkTop.Enabled = false; //this.lnkNext.Enabled = this.lnkLast.Enabled = true; //this.lnkFist.Attributes.Add("style", "color:#ced9df;"); this.lnkTop.Attributes.Add("style", "color:#ced9df;"); this.lnkNext.Attributes.Remove("style"); //this.lnkLast.Attributes.Remove("style"); } if (!pds.IsLastPage) { //Request.CurrentExecutionFilePath 为当前请求的虚拟路径 this.lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage + 1) + sbUrl; //this.lnkFist.Enabled = this.lnkTop.Enabled = true; //this.lnkNext.Enabled = this.lnkLast.Enabled = true; } else { //this.lnkNext.Enabled = this.lnkLast.Enabled = false; //this.lnkFist.Enabled = this.lnkTop.Enabled = true; this.lnkNext.Attributes.Add("style", "color:#ced9df;"); //this.lnkLast.Attributes.Add("style", "color:#ced9df;"); //this.lnkFist.Attributes.Remove("style"); //this.lnkTop.Attributes.Remove("style"); } //this.lnkFist.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);//跳转至首页 //this.lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(pds.PageCount);//跳转至末页 this.Repeater_PersonnelRosterList.DataSource = pds; this.Repeater_PersonnelRosterList.DataBind(); this.lbCurentPage.Text = (pds.CurrentPageIndex + 1).ToString(); this.lbCountPage.Text = pds.PageCount.ToString(); this.lbDataCount.Text = lymdlist.Count.ToString(); this.lbDataCount.Attributes.Add("style", "color:red;"); this.txtPageIndex.Text = this.lbCurentPage.Text.ToString(); this.BtnExportPersonnel.Attributes.Add("onclick", "return confirm(\'您确定要导出" + lymdlist.Count.ToString() + "条数据到表格?\')"); //判断用户是否有导出数据功能 if (Session["MasterInfo"] != null) { MasterInfo masterInfo = Session["MasterInfo"] as MasterInfo; MasterRoleMenuButtonService mrmbs = new MasterRoleMenuButtonService(); MasterRoleMenuButtonInfo mrmbInfo = mrmbs.GetMasterRoleMenuButtonInfo(masterInfo.RoleID.ToString(), BtnExportPersonnel.ID.ToString()); if (mrmbInfo != null) { BtnExportPersonnel.Visible = true; } } else { Response.Write("<script language=javascript>alert(\'登录超时!请重新登录\');parent.location.href=\'/login.html\';</script>"); Response.End(); } } /// <summary> /// 输入页码提交跳转 /// </summary> /// Thinkphp5 分页带参数