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>&nbsp;</span>
<asp:HyperLink ID="lnkNext" runat="server"><div class="fenyebtn"><img src="../images/ico/arrow_large_right.png" /></div></asp:HyperLink>&nbsp;
<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>&nbsp;
<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 = ;//定义分页每页初始大小

        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 = ;
} pds.CurrentPageIndex = CurrentPage - ;//当前页的索引就等于当前页码-1; if (!pds.IsFirstPage)
{
//Request.CurrentExecutionFilePath 为当前请求的虚拟路径
this.lnkTop.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - ) + 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 + ) + 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 + ).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>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkBtnToPage_Click(object sender, EventArgs e)
{ if (String.IsNullOrWhiteSpace(this.txtPageIndex.Text.ToString().Trim()))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('页码不能为空!')", true);
this.txtPageIndex.Focus();
return;
}
else
{
BindPersonnelRosterList();
}
}
/// <summary>
/// 导出数据到Excel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkBtnToExcel_Click(object sender, EventArgs e)
{ PageSize = ; BindPersonnelRosterList(); Export("application/ms-excel", "员工数据.xls");
}
/// <summary>
/// 导出数据函数
/// </summary>
/// <param name="FileType">导出文件MIME类型</param>
/// <param name="FileName">导出文件的名称</param>
private void Export(String FileType, String FileName)
{ Response.Clear();
Response.BufferOutput = true;
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
Repeater_PersonnelRosterList.RenderControl(hw);
string str = hw.InnerWriter.ToString();
Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\">");
Response.Write("</head><body><table>");
Response.Write(sw.ToString());
Response.Write("</table></body></html>");
Response.End(); }
/// <summary>
/// 如果需要实现导出Excel功能,则该函数需要重载,解释:确认在运行时为指定的ASP.NET 服务器控件呈现 HtmlForm 控件。
/// </summary>
/// <param name="control"></param>
public override void VerifyRenderingInServerForm(Control control) { } protected void LinkBtnSearch_Click(object sender, EventArgs e)
{
//恢复分页初始页为第一页
this.txtPageIndex.Text = "";
BindPersonnelRosterList();
} protected void Repeater_PersonnelRosterList_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "DeletePersonnel")
{
string personId = e.CommandArgument.ToString(); LuYongRosterService lyrs = new LuYongRosterService(); int num = lyrs.DeleteLuYongMingDanById(int.Parse(personId)); if (num > )
{
ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert('删除成功!');location='PersonnelManagement.aspx';", true);
return;
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "", "alert('删除失败!');location='PersonnelManagement.aspx';", true);
return;
}
}
} protected void Repeater_PersonnelRosterList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (Session["MasterInfo"] != null)
{
MasterInfo masterInfo = Session["MasterInfo"] as MasterInfo; if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
LuYongMingDanInfo tmskInfo = e.Item.DataItem as LuYongMingDanInfo;
//<a onclick="EditYuanGongState(<%# Eval("Id") %>);" title="编辑详情、价格调整" ></a>&nbsp;
LinkButton BtnDeletePersonnel = e.Item.FindControl("BtnDeletePersonnel") as LinkButton;
BtnDeletePersonnel.Attributes.Add("onclick", "return confirm('您确定要删除编号为:" + tmskInfo.Id.ToString() + "的人员信息?删除后无法恢复?')"); HyperLink BtnEditPersonnel = e.Item.FindControl("BtnEditPersonnel") as HyperLink;
BtnEditPersonnel.Attributes.Add("onclick", "EditYuanGongState('" + tmskInfo.Id.ToString() + "')"); MasterRoleMenuButtonService mrmbs = new MasterRoleMenuButtonService();
MasterRoleMenuButtonInfo mrmbInfo = mrmbs.GetMasterRoleMenuButtonInfo(masterInfo.RoleID.ToString(), BtnDeletePersonnel.ID.ToString());
if (mrmbInfo != null)
{
BtnDeletePersonnel.Visible = true;
} MasterRoleMenuButtonInfo mrmbInfo2 = mrmbs.GetMasterRoleMenuButtonInfo(masterInfo.RoleID.ToString(), BtnEditPersonnel.ID.ToString());
if (mrmbInfo2 != null)
{
BtnEditPersonnel.Visible = true;
}
}
}
else
{
Response.Write("<script language=JavaScript>alert('登录超时!请重新登录');parent.location.href='/login.html';</script>");
Response.End();
} }

代码解说:

private int PageSize = 8;//定义分页每页初始大小

之所以把pageSize定义为全局变量,并设置了固定的每页显示的条数,导出数据的时候,要把分页

PageSize = 0;然后再导出,要不然只能导出当前分页的第一个页面

StringBuilder sbUrl = new StringBuilder();

这个定义了一个可变字符串,要用它来储存筛选参数,

首先要判断this.txt_enterName.Value.ToString().Trim()这个文本框的值不为空或者非等于Null,将设置一个参数,把它写进sburl这个可变字符串中,多参数以此类推。。

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());

下面这句话就是把sbUrl这个字符串拼接到url分页中,放到最后即可

if (!pds.IsFirstPage)
{
//Request.CurrentExecutionFilePath 为当前请求的虚拟路径
this.lnkTop.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - ) + sbUrl;
//this.lnkFist.Enabled = this.lnkTop.Enabled = true;
//this.lnkNext.Enabled = this.lnkLast.Enabled = true;
}

然后在页面加载的时候进行判断,如果url中的参数不为空,就讲对应的参数赋值到对应的文本框中,这样就实现了url分页功能

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();
}

根据用户提供的索引值进行翻页,其实也很简单

/// <summary>
/// 输入页码提交跳转
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkBtnToPage_Click(object sender, EventArgs e)
{ if (String.IsNullOrWhiteSpace(this.txtPageIndex.Text.ToString().Trim()))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('页码不能为空!')", true);
this.txtPageIndex.Focus();
return;
}
else
{
BindPersonnelRosterList();//又重新绑定了数据源
}
}

BindPersonnelRosterList();中有这一段:

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 = ;
}

这样就实现了跳转,

注意在查询的时候,

protected void LinkBtnSearch_Click(object sender, EventArgs e)
{
//恢复分页初始页为第一页,这个一定要加,要不然,如果你翻页到第10页的时候,想重新查询数据,虽然查到数据,万一查到的数据没有10页怎么办,也得索引会停留在10上面
this.txtPageIndex.Text = "";
BindPersonnelRosterList();
}

导出表格其实和简单就是下面这三个方法:

/// <summary>
/// 导出数据到Excel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkBtnToExcel_Click(object sender, EventArgs e)
{ PageSize = ; BindPersonnelRosterList(); Export("application/ms-excel", "员工数据.xls");
}
/// <summary>
/// 导出数据函数
/// </summary>
/// <param name="FileType">导出文件MIME类型</param>
/// <param name="FileName">导出文件的名称</param>
private void Export(String FileType, String FileName)
{ Response.Clear();
Response.BufferOutput = true;
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
Repeater_PersonnelRosterList.RenderControl(hw);
string str = hw.InnerWriter.ToString();
Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\">");
Response.Write("</head><body><table>");
Response.Write(sw.ToString());
Response.Write("</table></body></html>");
Response.End(); }
/// <summary>
/// 如果需要实现导出Excel功能,则该函数需要重载,解释:确认在运行时为指定的ASP.NET 服务器控件呈现 HtmlForm 控件。
/// </summary>
/// <param name="control"></param>
public override void VerifyRenderingInServerForm(Control control) { }

repeater控件自定义Url分页带参数的更多相关文章

  1. asp.net动态网站repeater控件使用及分页操作介绍

    asp.net动态网站repeater控件使用及分页操作介绍 1.简单介绍 Repeater 控件是一个容器控件,可用于从网页的任何可用数据中创建自定义列表.Repeater 控件没有自己内置的呈现功 ...

  2. ASP.NET Repeater控件实现简单分页

    早上,有看MSDN,看到了 PagedDataSource 类 http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.pa ...

  3. .NetCore 实现分页控件(URL分页)实战

    上一篇文章介绍了分页控件的具体实现方式,接下来我们就来做一个分页控件 后台数据处理就过度的介绍,下面针对URL分页中的下面几点做说明: 1.搜索条件的状态保持 2.点击分页需要带上搜索条件 3.页码的 ...

  4. jQuery easyUI Pagination控件自定义div分页(不用datagrid)

    一般后台管理页面分页是通过datagrid加Pagination分页,但是如果前台页面没有用表格,例如博客的文章列表从上到下一般是到div分页, 这时如果还要用Pagination,则可以这样: 页面 ...

  5. repeater控件实现分页

    repeater控件实现排序的方法,今天我再向大家介绍repeater控件如何实现分页的效果. 分页分为真分页和假分页. 真分页:控件上一页需要显示多少数据,就从数据库取出并绑定多少数据,每次换页时都 ...

  6. SqlServer分页存储过程(多表查询,多条件排序),Repeater控件呈现数据以及分页

        存储过程(Stored Procedure)是在大型数据库系统中,一组为了完成特定功能的SQL 语句集,存储在数据库中,经过第一次编译后再次调用不需要再次编译,用户通过指定存储过程的名字并给出 ...

  7. Repeater控件的分页实现

    本文讲解Repeater控件与PagedDataSource相结合实现其分页功能.PagedDataSource 类封装那些允许数据源控件(如 DataGrid.GridView)执行分页操作的属性. ...

  8. Repeater控件使用(含删除,分页功能)

    Repeater控件使用(含删除,分页功能) 摘自:http://www.cnblogs.com/alanliu/archive/2008/02/25/914779.html 前臺代碼 <%@ ...

  9. 使用Sql分页方法给Repeater控件分页的方法

    页面代码 <div class="bookList"> <asp:Repeater ID="rpBooks" runat="serv ...

随机推荐

  1. js原型对象,每个new出来的新对象都有独立的原型对象__proto__

    刚才看一篇博文的时候, 动手测试了一下 JavaScript的原型链, 原型对象,发现每个构造器(赋给了某个 prototype ) new 出来的对象都有各自独立的原型对象 __proto__. p ...

  2. markdown表格

    markdown制作表格 一. 使用原生html表格标签制作 <table> <tr> <td>表头</td> </tr> <tr&g ...

  3. JQuery收集

  4. 注解用法详解——@SuppressWarnings

    一.前言 编码时我们总会发现如下变量未被使用的警告提示: 上述代码编译通过且可以运行,但每行前面的“感叹号”就严重阻碍了我们判断该行是否设置的断点了.这时我们可以在方法前添加 @SuppressWar ...

  5. VS2010与SVN

    http://blog.sina.com.cn/s/blog_4fe44775010182yl.html 在VS2010中使用SVN,必须先安装SVN的客户端,再安装VisualSVN(SVN的插件) ...

  6. [Unity Shader]ShaderForge制作Shader

    什么是ShaderForge ShaderForge的目标是推动统一的视觉质量提升到了新的高度, 给你自由的材质创建在一个视觉和直观的方式——不需要代码! ShaderForge的特性 •实时着色器预 ...

  7. mysql之SQL---存储过程

    1.存储过程简介  我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中,用 ...

  8. CORBA技术及实例

    CORBA技术及实例 CORBA是一种规范,它定义了分布式对象如何实现互操作.在WorldWideWeb盛行之前,非凡是java编程语言风靡之前,C++开发者基本将CORBA作为其高端分布式对象的解决 ...

  9. laravel5 html引用问题

    1. Composer 安装 编辑 composer.json 文件, require 节点下增加: "illuminate/html": "~5.0" 然后 ...

  10. 解决KVM中鼠标不同步问题

    VNCViewer中的鼠标走得总是比本地系统中的鼠标要慢,不同步,往往实体机中的鼠标都移出vnc窗口外边了,虚拟机中的鼠标指针还没移到需要点击的位置,操作起来很不方便. 起初的想法也是配置的问题,就按 ...