AspNetPage与Datalist实现分页的小问题!

xjl1314521wxw 2010-04-08 10:39:08
我用Datalist进行显示数据,用AspNetPage实现分页,但现在的问题是,我设置了AspNetPage的pagesize属性,但看不到效果,还是一页显示全部数据,别外,怎么把AspNetPage和datalist控件联系起来呢?
AspNetPage的分页存储过程是用来做什么的?
...全文
92 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
neorc99 2010-04-08
  • 打赏
  • 举报
回复
在C# 里面加入

page控件名.AllowPaging = true;

liaolian9948 2010-04-08
  • 打赏
  • 举报
回复
自己寫分頁的存儲過程吧。。。很容易實現的。。沒必要用別人的東西。初学多练练
sxy445566 2010-04-08
  • 打赏
  • 举报
回复
顶一下 关于AspNetPage我也不太清楚,学习!
yongxinai 2010-04-08
  • 打赏
  • 举报
回复
分页控件一般都用在后台或小型网站,如果前台页面分页的话建议楼主还是手写下吧!
lovehong123 2010-04-08
  • 打赏
  • 举报
回复
TextAfterInputBox="" TextBeforeInputBox="" UrlPaging="True" PrevPageText="上一页"
OnPageChanged="AspNetPager2_PageChanged" AlwaysShow="True">
</webdiyer:AspNetPager>
后台
this.Repeater1.DataSource = 数据源对象
this.Repeater1.DataBind();
this.AspNetPager2.PageSize = 页大小;
this.AspNetPager2.RecordCount = 页总数
 this.AspNetPager.2.PageIndex=页下标;
 this.AspNetPager2.Bind();

select top 10 * from 表名 where id not in(select top 10 id from 表名)
惜分飞 2010-04-08
  • 打赏
  • 举报
回复
上代码,不然没有办法说的
zyw2862944391 2010-04-08
  • 打赏
  • 举报
回复
你想让aspnetpager不够总数也显示把AlwaysShow="true" 设置一下,前台后台都可以
zhouing00 2010-04-08
  • 打赏
  • 举报
回复
我也遇到过同样的问题。你想想:如果datalist每页显示10条,可总的只有9条信息,怎么去分页呢?只有1页,AspNetPage是不显示滴
至于代码嘛
楼上的很正确
jack15850798154 2010-04-08
  • 打赏
  • 举报
回复
1,引用AspnetPage.dll到bin里
2,把Aspnetpage.dll添加到工具栏上来,好拖放
3,前台在数据绑定控件下面点加入(不好)

<webdiyer:AspNetPager ID="AspNetPager1" runat="server" CssClass="paginator" CurrentPageButtonClass="cpb"

onpagechanged="AspNetPager1_PageChanged"
CurrentPageButtonPosition="Center"
CustomInfoHTML="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条"
FirstPageText="首页" LastPageText="尾页" LayoutType="Table" NextPageText="下一页"
PageIndexBoxType="DropDownList" PagingButtonLayoutType="Span"
PrevPageText="上一页" ShowCustomInfoSection="Left" SubmitButtonText="Go"
TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到" AlwaysShow="True" PageSize="2">
</webdiyer:AspNetPager>


前台好////////////////////////////

<webdiyer:aspnetpager id="AspNetPager1" runat="server" buttonimagenameextension="n"
custominfohtml="共 %RecordCount% 条 页次 <font color='red'><b>%currentPageIndex%</b></font>/%PageCount% %PageSize% 条/页 次序 %StartRecordIndex%-%EndRecordIndex% 至 %RecordCount%"
custominfosectionwidth="" disabledbuttonimagenameextension="g" firstpagetext="<font face=webdings>9</font>"
font-italic="False" imagepath="/" lastpagetext="<font face=webdings>:</font>"
nextpagetext="<font face=webdings>4</font>" numericbuttontype="Text"
onpagechanged="AspNetPager1_PageChanged" prevpagetext="<font face=webdings>3</font>"
showcustominfosection="Left" shownavigationtooltip="True" showpageindexbox="Auto"
submitbuttontext="GO" width="600px" AlwaysShow="True" PageSize="20"></webdiyer:aspnetpager>


如果是有翻业的样式也是加在这里

4,后台绑定方法:
public void BindData()
{
string sql = "select * from phonecons where phonename like '%"+TextBox1.Text.ToString().Trim()+"%'";
DataTable datatable = Dbconn.datatable(sql);
PagedDataSource pds = new PagedDataSource();
AspNetPager1.RecordCount = datatable.Rows.Count;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.DataSource = Dbconn.datatable(sql).DefaultView;
pds.PageSize = AspNetPager1.PageSize;
Repeater1.DataSource = pds;
Repeater1.DataBind();
AspNetPager1.CustomInfoHTML = " 共 " + AspNetPager1.RecordCount.ToString() + " 条留言 "; //显示记录条数
AspNetPager1.CustomInfoHTML += " 当前 <font color=\"red\">" + AspNetPager1.CurrentPageIndex.ToString() + "</font>/" + AspNetPager1.PageCount.ToString() + " 页";//显示当前页/共多少页
}

5,在Aspnetpage的属性里设置每页数

6,给Aspnetpage添加翻页的代码

protected void AspNetPager1_PageChanged(object src, EventArgs e)
{

this.AspNetPager1.UrlRewritePattern = Request.CurrentExecutionFilePath + "?page={0}";//获取当前的虚拟路径+传递换页参数值
BindData();
}
zyw2862944391 2010-04-08
  • 打赏
  • 举报
回复
还有AspNetPage只是记录当前是第几页,分页还要靠自己写。
zyw2862944391 2010-04-08
  • 打赏
  • 举报
回复
前台
<webdiyer:AspNetPager ID="AspNetPager2" runat="server" CurrentPageButtonClass="cpb"
FirstPageText="首页" ForeColor="#FF6600" LastPageText="尾页" NextPageText="下一页" Font-Size="12px"
CustomInfoHTML="共%PageCount%页,当前为第%CurrentPageIndex%页,每页%PageSize%条" ShowBoxThreshold="11"
TextAfterInputBox="" TextBeforeInputBox="" UrlPaging="True" PrevPageText="上一页"
OnPageChanged="AspNetPager2_PageChanged" AlwaysShow="True">
</webdiyer:AspNetPager>
后台
this.Repeater1.DataSource = 数据源
this.Repeater1.DataBind();
this.AspNetPager2.PageSize = 页大小;
this.AspNetPager2.RecordCount = 页总数
jack15850798154 2010-04-08
  • 打赏
  • 举报
回复
AspNetPage的分页存储过程是用来做什么的?
AspNetPage的分页存储过程一般就是返回一个“总页数”等。
怎么把AspNetPage和datalist控件联系起来呢?
你应该添加一个
this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;

AspNetPager1.RecordCount = 5; --每页多少条数据
webdiyer 2010-04-08
  • 打赏
  • 举报
回复
怎么发两个相同的帖子哪?楼主不太了解AspNetPager的分页原理,我在上一个帖子中已经回复过了,分页控件和数据没有直接关系,在实现分页,一般都是编写PageChanged事件处理程序,在这个处理程序中获取当前页数据并绑定或显示,看一下示例很容易理解的。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧