求分页思路啊,整了几天了,一筹莫展

CSHUALOP 2012-09-10 09:39:42
我在做一个留言板,想把数据库某表中的记录逐条分页显示出来,就像csdn论坛这种样式(完了还有管理,回复等功能),请教具体步骤跟方法思路,不要贴链接,我看过好多个了,要么老长不知如何套用,麻烦前辈耐心指点一下,越详细越好了,(创建什么文件开始),在线等,弄好速度给分
...全文
298 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
CSHUALOP 2012-09-12
  • 打赏
  • 举报
回复
谢谢大家的回帖,现在火候不到家,先去好好学学sql,再回来整这个,开始发分喽
net5354 2012-09-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
分页可以用AspNetPager,示例在这里:http://webdiyer.com/AspNetPagerDemo/default.aspx
[/Quote]我也用了你以前的版本,但设置数据源有点复杂
E次奥 2012-09-11
  • 打赏
  • 举报
回复
LZ要真分页还是假分页啊。

两个分页的方法略有不同啊。

1.查出数据库所有记录,每页显示10行。

2.每次查10条记录显示出来,下一页从上一页的最后一个记录id的下一个id开始查10条记录!

思路就上边两个方法。

貌似用reapeat是比较好的。


ASPNETCHENGXU 2012-09-11
  • 打赏
  • 举报
回复
告诉你我经常的做法吧。
用reapeat控件
1. 肯定是做好了界面了,然后把要循环的html放入
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
/***这里放要循环的html,在指定的地方放入要绑定的数据,***/

</ItemTemplate>
</asp:Repeater>

2. 在后台给Repeater绑定数据就行了

3. 分页的话,你直接在网上搜搜Repeater自定义分页就行了


我是很烦用那些第三方空间的

yyl8781697 2012-09-11
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

引用 1 楼 的回复:

分页可以用AspNetPager,示例在这里:http://webdiyer.com/AspNetPagerDemo/default.aspx


我倒觉得你用这个挺不错,先用懂了,熟了。再自己写就简单多了。
[/Quote]
++++
赞成,之前一直用AspNetPager控件,后来自己写了个简单版的满足自己需求的,相对自己可控性更加高的东西
自定义分页方法
wangyizhi58 2012-09-11
  • 打赏
  • 举报
回复
http://blog.csdn.net/wangyizhi58/article/details/7914582 看看吧或许有帮助
盗版 2012-09-11
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
引用 1 楼 的回复:

分页可以用AspNetPager,示例在这里:http://webdiyer.com/AspNetPagerDemo/default.aspx


二楼的这个控件非常好用,我一直在用。推荐你试试。另外,感谢二楼。
[/Quote]

我也推荐用这个,简单易用,使用方法里面很详细
CSHUALOP 2012-09-11
  • 打赏
  • 举报
回复
我现在就是不知道怎么连接数据源了,研究了一下貌似还要去sql写一个存储过程,顺便问下可以给个例子吗?[Quote=引用 17 楼 的回复:]

引用 1 楼 的回复:
分页可以用AspNetPager,示例在这里:http://webdiyer.com/AspNetPagerDemo/default.aspx
我也用了你以前的版本,但设置数据源有点复杂
[/Quote]
WJY_123456 2012-09-11
  • 打赏
  • 举报
回复
linq skip() Take()可轻松实现分页
songjinxi123 2012-09-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

分页可以用AspNetPager,示例在这里:http://webdiyer.com/AspNetPagerDemo/default.aspx
[/Quote]

二楼的这个控件非常好用,我一直在用。推荐你试试。另外,感谢二楼。
ycproc 2012-09-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

分页可以用AspNetPager,示例在这里:http://webdiyer.com/AspNetPagerDemo/default.aspx
[/Quote]

我倒觉得你用这个挺不错,先用懂了,熟了。再自己写就简单多了。
Boring_life 2012-09-10
  • 打赏
  • 举报
回复
前台 代码

<asp:Label ID="lb_MessageCount" runat="server" ForeColor="red "></asp:Label>
<asp:LinkButton ID="FirstLB" runat="server" Font-Size="Small" OnClick="FirstLB_Click">首页</asp:LinkButton>
 
<asp:LinkButton ID="PreviousLB" runat="server" Font-Size="Small" OnClick="PreviousLB_Click">上一页</asp:LinkButton>
 
<asp:Label ID="lb_CurrentPage" runat="server" Font-Size="Small" Text="Label"></asp:Label>
<asp:Label ID="lb_fenge" runat="server" Text="/"></asp:Label>
<asp:Label ID="lb_PageCount" runat="server" Font-Size="Small" Text="Label"></asp:Label>
<asp:LinkButton ID="NextLB" runat="server" Font-Size="Small" OnClick="NextLB_Click">下一页</asp:LinkButton>
 
<asp:LinkButton ID="EndLB" runat="server" Font-Size="Small" OnClick="EndLB_Click">尾页</asp:LinkButton>
<br/>

<div >
<center>
<asp:DataList ID="dl_ShowMessage" runat="server" CellSpacing="5"
GridLines="Both" Height="515px" style="margin-left: 0px" Width="700px"
onitemcommand="dl_ShowMessage_ItemCommand"
onitemdatabound="dl_ShowMessage_ItemDataBound" BackColor="#CCCCCC">
<ItemTemplate>
<table cellspacing="0" style="border:#ffffc solid 1px;" width="680">
<tr>
<td rowspan="4">

<center>
<image border="0" height="100" src="images/1.jpg" width="100" />
</center>

<center>
<asp:Label ID="lb_Person" runat="server" Font-Size="Small"><%#Eval("person")%></asp:Label>
</center>
</td>
<td height="20" width="80%">
<div align="left">
<asp:Label ID="lb_Info" runat="server" Font-Size="Small">第<%#Eval("no") %>楼
<%#Eval("date") %></asp:Label>
<asp:Label ID="lb_MessageNo" runat="server" Text='<%#Eval("no")%>' Visible="false"></asp:Label>
</div>
</td>
</tr>
<tr>
<td height="100" width="80%">
<div align="left">
<asp:TextBox ID="txt_ShowMessage" runat="server" Width="560px" Height="80px"
BorderStyle="None" BackColor="#CCCCCC" TextMode="MultiLine" readOnly="true"
Font-Size="Medium" Text='<%#Eval("message") %>'></asp:TextBox>
</div>
</td>
</tr>
<tr>
<td height="20" width="80%">
<div align="right">

<input id="txt_Content_<%#Container.ItemIndex %>" type="button" value="回复留言"
onclick="display(<%#Container.ItemIndex %>)" style="border-style: none" />
<asp:LinkButton ID="Linkbt_delete" runat="server" Font-Size="Small" ForeColor="Red" CommandName="Linkbt_delete" Text="删除留言"></asp:LinkButton>
<script type="text/javascript">
function display(j) {
document.getElementById("txt_Content_"+j).style.display="none";
document.getElementById("abc"+j).style.display="block";
}
</script>
<div id="abc<%#Container.ItemIndex%>" style="display:none" >
<asp:TextBox ID="txt_MessageReply" runat="server" Width="600px" Height="20px"
BorderStyle="Groove" TextMode="MultiLine" CommandName="txt_MessageReply" ></asp:TextBox>
<asp:Button ID="bt_SubmitReplay" runat="server" CommandName="bt_SubmitReply" Text="提交"/>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div>
<asp:DataList ID="dl_ShowMessageReply" runat="server" BackColor="#CCCCCC" onItemDataBound="dl_ShowMessage_ItemDataBound"
onItemCommand="dl_ShowMessage_ItemCommand" GridLines="Both">
<ItemTemplate>
<table cellspacing="0" width="600">
<tr>
<td rowspan="2">
<center>
<img border="0" src='<%#Eval("replyPersonImage")%>' style="height: 30px; width: 30px" />
<br>
</br>
<asp:Label ID="lb_ReplyPerson" runat="server" Font-Size="Small" Text='<%#Eval("replyPerson")%>'></asp:Label>
</center>
</td>
<td width="90%">
<center>
<asp:TextBox ID="txt_ShowMood" runat="server" BackColor="#CCCCCC" textMode="MultiLine" BorderStyle="Ridge"
readOnly="true" width="540px" Height="20px" Font-Size="Small" Text='<%#Eval("replyContent")%>'></asp:TextBox>
<asp:Label ID="lb_ReplyNo" runat="server" Text='<%#Eval("no")%>' Visible="false"></asp:Label>
</center>
</td>
</tr>

<tr>
<td width="85%">
<asp:Label ID="lb_replyTime" runat="server" Font-Size="Small" ForeColor="#FF3300"><%#Eval("replyTime")%></asp:Label>
                
                
     
<asp:LinkButton ID="Linkbt_deleteReply" runat="server" CommandName="Linkbt_deleteReply" Font-Size="Small" ForeColor="red" Text="删除" ></asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</center>
</div>
Boring_life 2012-09-10
  • 打赏
  • 举报
回复
我做的留言板 跟CSDN类似 有回复功能
管理吗 只有 删除 留言 删除 回复

用DataList 控件 回复的话 在DataList里面嵌套一个DataList
这是后台给DataList 绑定数据 分页代码

public void DataListBind() //将数据绑定到Datalist控件
{
string connectString = @"Data Source=.;Initial Catalog=MyWeb;User ID=sa;Password=123456";
SqlConnection conn = new SqlConnection(connectString);
string sqlStr = "select * from Message order by no desc";
SqlDataAdapter sda = new SqlDataAdapter(sqlStr, conn);
DataSet ds = new DataSet();
sda.Fill(ds, "pro");
//创建数据源
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["pro"].DefaultView;
//允许分页
pds.AllowPaging = true;
//设置每页显示记录数
pds.PageSize = 5;
//获取总页数
pageCount = pds.PageCount;
this.lb_PageCount.Text = pageCount.ToString();
pds.CurrentPageIndex = currentPage - 1;
//当前页
this.lb_CurrentPage.Text = Convert.ToString(currentPage);
//数据绑定
this.dl_ShowMessage.DataSource = pds;
this.dl_ShowMessage.DataBind();
}
/// <summary>
/// 上一页 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void PreviousLB_Click(object sender, EventArgs e)
{
if (this.lb_CurrentPage.Text != "1")
{
currentPage = int.Parse(this.lb_CurrentPage.Text) - 1;
this.lb_CurrentPage.Text = currentPage.ToString();
DataListBind();
}
}
/// <summary>
/// 下一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void NextLB_Click(object sender, EventArgs e)
{
if (this.lb_PageCount.Text == this.lb_CurrentPage.Text)
{
}
else
{
currentPage = int.Parse(this.lb_CurrentPage.Text) + 1;
this.lb_CurrentPage.Text = currentPage.ToString();
DataListBind();
}
}
/// <summary>
/// 第一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void FirstLB_Click(object sender, EventArgs e)
{
if (this.lb_CurrentPage.Text == "1")
{

}
else
{
currentPage = 1;
DataListBind();
}
}
/// <summary>
/// 最后一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void EndLB_Click(object sender, EventArgs e)
{
this.lb_CurrentPage.Text = this.lb_PageCount.Text;
currentPage = int.Parse(this.lb_CurrentPage.Text);
DataListBind();
}


相当之稳重 2012-09-10
  • 打赏
  • 举报
回复
思路无非是从数据库里读取 第n条到第m条的数据。。其中这个n和m是根据你需要分页的每页条数决定的。比如你15条数据分3页显示,你要查看第二页的数据就查询第6到第10条数据。数据库查询的部分自己写存储过程或者SQL语句了,分页控件的话可以用 AspNetPager ,用法可以参考 http://blog.csdn.net/ptyzhu/article/details/7911708
webdiyer 2012-09-10
  • 打赏
  • 举报
回复
wulei_ciety 2012-09-10
  • 打赏
  • 举报
回复
给你个比较好点的思路,先读数据库200条数据,存放在一个DATATABLE中,每页显示20条,当翻到10也或者该页面刷新的时候在去数据库抓取200条数据,抓多少数据看你分页了,这样能解决你数据库数据过多而导致分页卡,则不需要每次翻页都对数据库读取。
CSHUALOP 2012-09-10
  • 打赏
  • 举报
回复
好多错误啊,是在aspx里面写的吗?[Quote=引用 3 楼 的回复:]

我做的留言板 跟CSDN类似 有回复功能
管理吗 只有 删除 留言 删除 回复

用DataList 控件 回复的话 在DataList里面嵌套一个DataList
这是后台给DataList 绑定数据 分页代码
C# code

public void DataListBind() //将数据……
[/Quote]
CSHUALOP 2012-09-10
  • 打赏
  • 举报
回复
上面引用无关,麻烦用过二楼控件的给看看
CSHUALOP 2012-09-10
  • 打赏
  • 举报
回复
我下了二楼的源文件,有些地方不知到怎么改:
如PageDataList部分,单独调试时出现下列错误,请大家帮忙看看
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int totalOrders = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetOrderNumber");
AspNetPager1.RecordCount = totalOrders;
bindData();
}
}

其中int totalOrders = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetOrderNumber");
报错,错误提示为:SqlHelper”的类型初始值设定项引发异常。;
[Quote=引用 4 楼 的回复:]

前台 代码
HTML code

<asp:Label ID="lb_MessageCount" runat="server" ForeColor="red "></asp:Label>
<asp:LinkButton ID="FirstLB" runat="server" Font-Size="Small" OnClick="FirstLB_Click">首页</asp:LinkB……
[/Quote]
woshimaikou 2012-09-10
  • 打赏
  • 举报
回复
可以使用一些现成的控件,但自己最好研究下原理,代码之类的,对自己提高有帮助的

62,248

社区成员

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

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

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

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