我来做百科(第二十天) C
我看到百度贴吧的评论,在会员后台点击评论后会自动跳到该评论所在的页码的页面,而不是简单的锚。我也要做做看。在csdn问了问,估计直接根据id直接取分页数据的话会比较麻烦,所以决定做法是先找到评论所在页的页码,再根据页码来获取该分页的数据。这样就只是一个问题,就是如何根据评论id获取它的所在分页页码。又取csdn问了问,高手果然很多,再结合需要,得到代码如下:
/// <summary>
/// 获取指定lemma的评论的所在页码
/// </summary>
/// <param name="PageSize">每页显示数</param>
/// <param name="id">id</param>
/// <param name="lemma">lemma</param>
public int GetCommentPageByIdAndLemma(int PageSize, int id, int lemma)
{
StringBuilder strSQL = new StringBuilder();
strSQL.Append("select count(1) ").Append(FROM_TABLE).Append(" where id > ").Append(id).Append(" and lemmaid = ").Append(lemma);
![](/Images/OutliningIndicators/InBlock.gif)
int iCount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.Text, strSQL.ToString(), null).ToString());
![](/Images/OutliningIndicators/InBlock.gif)
int iPage = Convert.ToInt32(iCount / PageSize);
![](/Images/OutliningIndicators/InBlock.gif)
if (iCount % PageSize > 0) iPage++;
![](/Images/OutliningIndicators/InBlock.gif)
return iPage;
}
获取了页码剩下的就简单了,不错的功能。
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
获取了页码剩下的就简单了,不错的功能。
转载请注明出处:http://www.cnblogs.com/cloudgamer/
如有任何建议或疑问,欢迎留言讨论。
如果觉得文章不错的话,欢迎点一下右下角的推荐。
程序中包含的js工具库CJL.0.1.min.js,原文在这里。