原先是用的第三方控件AspNetPager.dll来实现的分页,感觉吧还行...后来弄SEO的时候,老大跑来找我了,蜘蛛采集不到?我晕意思就是说我的改了吧
没办法只能从新弄了,因此就网上找找了,感觉这个还是可以的...
源码:用的三层,换成你自己的
.cs代码
int ToatalCountRecord;//总记录数
int PageItem = 8;//每页显示的条数
int CurrentPage = 1;//当前页数
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["page"] != null)
{
string a = Request.QueryString["page"];
CurrentPage = Convert.ToInt32(a);
}
GetVproduct(43);
}
}
{
DataTable dt = vPrdouctRules.GetProBybrandid(brandid);
if (dt.Rows.Count > 0)
{
string where = " brandid =" + brandid + " and DeleteFlag=0 and Gbisweb='Y' and IsSpecial=0";
rpVproduct.DataSource = vPrdouctRules.Select(PageItem, CurrentPage, where, "autoid", true, false);
rpVproduct.DataBind();
}
else
{
product1.Visible = false;
}
ToatalCountRecord = dt.Rows.Count;
BuildPages();
}
private void BuildPages()
{
int Step = 5;//偏移量
int LeftNum = 0;//左界限
int RightNum = 0;//右界限
string seoName = BrandVsSeoRule.GetModelByBid(Convert.ToInt32(brandid)).SeoName;
string PageUrl = brandDetail;
int PageCount = (int)Math.Ceiling((double)(ToatalCountRecord) / PageItem);
if (CurrentPage - Step < 1)
{
LeftNum = 1;
}
else
{
LeftNum = CurrentPage - Step;
}
if (CurrentPage + Step > PageCount)
{
RightNum = PageCount;
}
else
{
RightNum = CurrentPage + Step;
}
StringBuilder OutPut = new StringBuilder();
OutPut.Append("<ul>");
if (CurrentPage != 1)
{
OutPut.Append(" <li><span> <a href='" + PageUrl + "/" + seoName + "/" + brandid + "_" + (CurrentPage - 1) + ".html" + "'>" + "<" + " </a></span></li>");
}
else
{
OutPut.Append("<li class='pageno'><span><a href='#'><</a></span></li>");
}
for (int i = LeftNum; i <= RightNum; i++)
{
if (i == CurrentPage)
{
OutPut.Append("<li class='on'><a href='" + PageUrl + "/" + seoName + "/" + brandid + "_" + i.ToString() + ".html" + "'> " + " " + i.ToString() + "" + "</a></li>");//自己拼写自己的样式,我们美工做好的UL里面LI
}
else
{
OutPut.Append("<li> <a href='" + PageUrl + "/" + seoName + "/" + brandid + "_" + i.ToString() + ".html" + "'>" + " " + i.ToString() + " " + " </a></li>");
}
}
if (CurrentPage < PageCount)
{
OutPut.Append("<li> <span> <a href='" + PageUrl + "/" + seoName + "/" + brandid + "_" + (CurrentPage + 1) + ".html" + "'>" + ">" + " </a></span></li>");
}
else
{
OutPut.Append("<li class='pageno'><span><a href='#'>></a></span></li>");
}
OutPut.Append("</ul>");
this.product1.InnerHtml = OutPut.ToString();
}
.aspx代码
<asp:Repeater ID="rpVproduct" runat="server" >
<ItemTemplate>
<%#Eval("PrcName")%>
</ItemTemplate>
</asp:Repeater>
<div class="page" id="product1" runat="server">
</div>