1
1楼 WebZlan 2007-01-17 23:12:15 这是我的分页代码.我只能让所有页码全输入来,但是我想只显示10页如; 1 2 3 4 5 6 7 8 9 10 然后点10页的时候就显示10 11 12 .. 20.这么做? protected void Page_Load(object sender, EventArgs e) { int n; if (!Page.IsPostBack) { if (Request.QueryString[ "page "] != null) { n = Convert.ToInt32(Request.QueryString[ "page "]); } else { n = 0; } bind(n); } } private void bind(int n) { DB db = new DB(); DataList1.DataSource = db.pds(n); DataList1.DataBind(); } protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Footer) { PlaceHolder ph = (PlaceHolder)e.Item.FindControl( "ph "); DB db=new DB(); for (int i = 0; i < db.pds().PageCount;i++ ) { HyperLink hl = new HyperLink(); Literal nsb = new Literal(); int n = i + 1; hl.ID = n.ToString(); hl.Text = n.ToString(); hl.NavigateUrl = "Default2.aspx?page= " + i; nsb.Text = " "; ph.Controls.Add(hl); ph.Controls.Add(nsb); } } } =========DB类========== public class DB { protected string connString; private int pagesize; public DB() { connString = ConfigurationManager.ConnectionStrings[ "pubsConnectionString "].ConnectionString; pagesize = 4; // // TODO: 在此处添加构造函数逻辑 // } public DataView dt(string selString) { SqlConnection conn = new SqlConnection(connString); SqlDataAdapter sda = new SqlDataAdapter(selString,conn); DataSet ds = new DataSet(); sda.Fill(ds, "name "); return ds.Tables[ "name "].DefaultView; } public int sql(string sqlStr) { SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(sqlStr,conn); conn.Open(); int er = cmd.ExecuteNonQuery(); conn.Close(); return er; } public PagedDataSource pds(int pageCurrent) { PagedDataSource pds = new PagedDataSource(); pds.DataSource = this.dt( "select * from authors "); pds.AllowPaging = true; pds.CurrentPageIndex = pageCurrent; pds.PageSize = pagesize; return pds; } public PagedDataSource pds() { PagedDataSource pds = new PagedDataSource(); pds.DataSource = this.dt( "select * from authors "); pds.AllowPaging = true; pds.PageSize = pagesize; return pds; } } 2楼 nikolas 2007-01-18 00:40:20 我是先写个分页的SQL语句结合Repeater,然后用Javascript可以实现你说的这种效果。 3楼 nikolas 2007-01-18 00:50:45 你的Sql语句修改下就不会全部显示了 select * from authors 改为 select top N * from authors 4楼 webdiyer 2007-01-18 08:51:56 自己写太费劲了,你可以试试我的AspNetPager免费分页控件:http://www.webdiyer.com 今天机房维护,主页上午不能访问了,下午3点以后应该好了 5楼 WebZlan 2007-01-18 13:37:58 楼上的朋友我下载你了控件,有没有使用帮助呀, 给我发lanaiduo@sina.com 6楼 webdiyer 2007-01-18 18:32:48 晕,楼主没看仔细,下载页面上不是有 AspNetPagerDoc.rar AspNetPager 6.0.0 for Visual Studio 2005 帮助文档。 这个就是帮助文档 7楼 nnh 2007-01-18 20:17:35 webdiyer的就很不错. 8楼 wtsdesigner 2007-01-19 21:16:44 WTS分页三剑侠 http://community.csdn.net/Expert/topic/5290/5290374.xml?temp=.4305994 9楼 syeerzy 2007-01-19 21:21:41 貌似楼主自己都不知道自己写的代码是怎么工作的。。。。
搜索墙@2009 www.pkwall.com all rights reserved QQ:276471788 [京ICP备09111534号]
声明:本站部分数据来源于网络,仅供参考,如有版权问题,请联系我们,我们将及时删除!转载本站请注明来源
| |||||