要先下载aspnetpager的dll文件,选择项加载进去 前台代码(没有加样式的) <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" CenterCurrentPageButton="True" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PageSize="20" PrevPageText="上一页" onpagechanging="AspNetPager1_PageChanging"> </webdiyer:AspNetPager> 前台代码(使用了样式) <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" CenterCurrentPageButton="True" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PageSize="10" PrevPageText="上一页"OnPageChanging="AspNetPager1_PageChanging" AlwaysShowFirstLastPageNumber="True"PageIndexBoxType="DropDownList" CssClass="pages" CurrentPageButtonClass="cpb"ShowPageIndexBox="Always" PagingButtonSpacing="2px"> </webdiyer:AspNetPager> 这个是后来师兄给的,使用了2个ds,做药检的时候,发现,一个就够了! public void bangding() { string sql = " 获取sql语句"; DataSet ds = sqlhelper.GetDataSet(sql); int count = ds.Tables[0].Rows.Count; AspNetPager1.RecordCount = count; SqlDataAdapter da = sqlhelper.GetDataAdapter(sql); DataSet ds2 = new DataSet(); da.Fill(ds2, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "jieguo"); GridView1.DataSource = ds2.Tables[0].DefaultView; //注意数据源 GridView1.DataBind(); } protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { AspNetPager1.CurrentPageIndex = e.NewPageIndex; Rep_Bind(); } protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { AspNetPager1.CurrentPageIndex = e.NewPageIndex; bangding(); //注意要重新绑定 } 这个是做药检的时候,用的一个方法,详见: http://hi.baidu.com/afantihome/blog/item/efbc82d33959d7dda9ec9aba.html protected void Rep_Bind() { select_sql = "select * from drugsample "; OleDbDataAdapter sda = sqlhelper.QueryAdapter(select_sql); DataSet ds = new DataSet(); sda.Fill(ds, "count"); sda.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "temptbl"); AspNetPager1.RecordCount = ds.Tables["count"].Rows.Count; Repeater1.DataSource = ds.Tables["temptbl"]; Repeater1.DataBind(); } 另附上CSS的代码,觉得这个样式不错,红色的 body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; font-size: 14px; } .www_zzjs_net { display: none; position: absolute; top: 25%; left: 25%; width: 50%; height: 50%; padding: 16px; border: 16px solid orange; background-color: white; z-index: 1002; overflow: auto; } .pages { color: #999; margin: 10px 200px; } .pages a, .pages .cpb { text-decoration: none; float: left; padding: 0 5px; border: 1px solid #ddd; background: #ffff; margin: 0 2px; font-size: 11px; color: #000; } .pages a:hover { background-color: #E61636; color: #fff; border: 1px solid #E61636; text-decoration: none; } .pages .cpb { font-weight: bold; color: #fff; background: #E61636; border: 1px solid #E61636; }