标签:
前台代码:
1 <div style="height:1135px;border:solid 1px #808080;"> 2 3 <div id="ssigeer"> 4 <ul> 5 <li><a href="caseli.aspx">知名客户</a></li> 6 <li><a href="caseer.aspx">地区分类</a></li> 7 <li><a href="casesan.aspx">行业分类</a></li> 8 <li><a href="caseguo.aspx">国际案例</a></li> 9 </ul> 10 </div> 11 12 <div id="anniu"> 13 <ul> 14 <li><a href="caseer.aspx">全部</a></li> 15 <li><a href="caseer.aspx?id=1">北京</a></li> 16 <li><a href="caseer.aspx?id=2">山东</a></li> 17 <li><a href="caseer.aspx?id=3">上海</a></li> 18 <li><a href="caseer.aspx?id=4">江苏</a></li> 19 <li><a href="caseer.aspx?id=5">浙江</a></li> 20 <li><a href="caseer.aspx?id=6">陕西</a></li> 21 <li><a href="caseer.aspx?id=7">天津</a></li> 22 <li><a href="caseer.aspx?id=8">河北</a></li> 23 <li><a href="caseer.aspx?id=9">湖北</a></li> 24 <li><a href="caseer.aspx?id=10">河南</a></li> 25 <li><a href="caseer.aspx?id=11">四川</a></li> 26 <li><a href="caseer.aspx?id=12">湖南</a></li> 27 <li><a href="caseer.aspx?id=13">福建</a></li> 28 <li><a href="caseer.aspx?id=14">黑龙江</a></li> 29 <li><a href="caseer.aspx?id=15">云南</a></li> 30 <li><a href="caseer.aspx?id=16">吉林</a></li> 31 <li><a href="caseer.aspx?id=17">重庆</a></li> 32 <li><a href="caseer.aspx?id=18">内蒙</a></li> 33 </ul> 34 </div> 35 36 <div id="sjuti"> 37 38 <asp:DataList ID="DataList1" runat="server" RepeatColumns="4" > 39 <ItemTemplate> 40 <div id="jutiyi"> 41 <asp:Label ID="nameLabel" runat="server" Text=‘<%# Eval("name") %>‘ /> 42 <br /> 43 <asp:Label ID="contectLabel" runat="server" Text=‘<%# Eval("contect") %>‘ /> 44 <br /> 45 <br /></div> 46 </ItemTemplate> 47 </asp:DataList> 48 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:xtConnection %>" SelectCommand="SELECT [name], [contect] FROM [case_address] WHERE ([type] = @type)"> 49 <SelectParameters> 50 <asp:QueryStringParameter DefaultValue="1" Name="type" QueryStringField="id" Type="Int32" /> 51 </SelectParameters> 52 </asp:SqlDataSource> 53 54 <div id="fenye" runat="server" style="position: absolute; margin-left: 268px;margin-top:50px;" > 55 <table> 56 <tr><td> 57 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 58 <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> 59 <asp:HyperLink ID="HyperLink1" runat="server">上一页</asp:HyperLink> 60 <asp:HyperLink ID="HyperLink2" runat="server">下一页</asp:HyperLink></td> 61 </tr> 62 </table> 63 </div> 64 </div> 65 </div>
后台代码:
1 protected void Page_Load(object sender, EventArgs e) 2 { 3 MaintainScrollPositionOnPostBack = true; 4 DataListBind(); 5 buxianshi(); 6 }
1 private void DataListBind() 2 { 3 PagedDataSource PDS = new PagedDataSource(); 4 PDS.DataSource = SqlDataSource1.Select(DataSourceSelectArguments.Empty); 5 //连接数据源 6 PDS.AllowPaging = true; 7 PDS.PageSize = 32;//每页显示32个数据 8 PDS.CurrentPageIndex = CurrentPage() - 1; 9 DataList1.DataSource = PDS; 10 DataList1.DataBind(); 11 12 13 Label1.Text = "第" + (PDS.CurrentPageIndex + 1).ToString() + "页"; 14 Label2.Text = "/共" + PDS.PageCount.ToString() + "页"; 15 16 17 if (!PDS.IsFirstPage) 18 { 19 //HyperLink1.NavigateUrl = "caseer.aspx?id=3&page=" + (CurrentPage() - 1).ToString(); 20 HyperLink1.NavigateUrl = "caseer.aspx?id=" + CurrentPaged().ToString() + "&page=" + (CurrentPage() - 1).ToString(); 21 } 22 if (!PDS.IsLastPage) 23 { 24 //HyperLink2.NavigateUrl = "caseer.aspx?id=3&page=" + (CurrentPage() + 1).ToString(); 25 HyperLink2.NavigateUrl = "caseer.aspx?id=" + CurrentPaged().ToString() + "&page=" + (CurrentPage() + 1).ToString(); 26 } 27 } 28 29 private int CurrentPage()//取出正确的页数当作参数 30 { 31 if (Request["Page"] != null) 32 { 33 return Convert.ToInt16(Request["Page"]); 34 } 35 else 36 { 37 return 1; 38 } 39 } 40 41 private int CurrentPaged()//从前台取出正确的id 当作参数 42 { 43 if (Request["id"] != null) 44 { 45 return Convert.ToInt16(Request["id"]); 46 } 47 else 48 { 49 return 1; 50 } 51 } 52 53 private void buxianshi() 54 { 55 PagedDataSource PDS = new PagedDataSource(); 56 PDS.DataSource = SqlDataSource1.Select(DataSourceSelectArguments.Empty); 57 PDS.AllowPaging = true; 58 PDS.PageSize = 32; 59 PDS.CurrentPageIndex = CurrentPage() - 1; 60 if(PDS.PageCount==1) 61 { 62 fenye.Visible = false;//如果页数等于1,则不显示分页的div,页面加载时执行。 63 } 64 }
标签:
原文地址:http://www.cnblogs.com/yisen-1/p/4238791.html