文章过长 设置分页问题

jy02409187 2009-09-11 10:03:18
如果文章过长,怎样设置到一定的字节数就转到下一页啊
<asp:Repeater ID="RepArt" runat="server">
<ItemTemplate>
<div id="d22"><%#DataBinder.Eval(Container.DataItem,"news_title")%></div>
<div id="d23">时间:<%# DataBinder.Eval(Container.DataItem,"news_time") %>      点击:<%# DataBinder.Eval(Container.DataItem,"news_hit") %></div>
<div id="d24"><%# DataBinder.Eval(Container.DataItem,"news_leiyong") %></div>
</ItemTemplate>
</asp:Repeater>


这个是读取文章的<%# DataBinder.Eval(Container.DataItem,"news_leiyong") %> 谢谢各位啊
...全文
227 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
jy02409187 2009-09-26
  • 打赏
  • 举报
回复
因为我是刚学习C#,所以对大部分控件都不是很熟悉,觉得能用就可以了,以后我会注意的,谢谢教导.
jy02409187 2009-09-26
  • 打赏
  • 举报
回复
那个我已经把控件给去掉了 现在前台是以<div><%=Name%></div> 直接出来的
我用gui0605的方法时出了一点问题
<asp:Label ID="labContent" runat="server"> <%=Name%>
<br />
<asp:Label ID="labPageNumber" runat="server"> </asp:Label> </asp:Label>

错误信息 当前上下文中不存在名称“m_strRet”
希望可以再帮一下忙
gui0605 2009-09-25
  • 打赏
  • 举报
回复
你只显示内容而已,为什么要用Repeater控件?这个用得莫名其妙,白白浪费资源
jy02409187 2009-09-24
  • 打赏
  • 举报
回复
没解决
jy02409187 2009-09-23
  • 打赏
  • 举报
回复
<asp:Repeater ID="RepArt" runat="server">
<ItemTemplate>
<div id="d22"><p class="c4"><%#DataBinder.Eval(Container.DataItem,"news_title")%></p></div>
<div id="d23">时间:<%#DataBinder.Eval(Container.DataItem,"news_time") %>      点击:<%# DataBinder.Eval(Container.DataItem,"news_hit") %></div>
<div id="d24"><p class="c4">        <asp:Label ID="labContent" runat="server"><%#DataBinder.Eval(Container.DataItem,"news_leiyong")%></p></asp:Label></div>
</ItemTemplate>
</asp:Repeater>

哪个如果在 repeater里面再用<asp:Label ID="labContent" runat="server"> </asp:Label>
后台的labContent是传不到过来的. 怎么办啊各位高手们,这个问题已经困扰我好久好久了....
jy02409187 2009-09-23
  • 打赏
  • 举报
回复
头晕啊头晕啊 求高手啊!!!!!!!!
flyerwing 2009-09-23
  • 打赏
  • 举报
回复
估计得截取吧。
liujintaozyc 2009-09-23
  • 打赏
  • 举报
回复
太汗了
不要把内容放rpt里
可以放其他地方
至于分页吧 你可以加个特殊符号 然后进行分页
gui0605 2009-09-22
  • 打赏
  • 举报
回复
private string OutputArticle()
{//Only output one Record of the "AriticID" is 2
string m_strRet = "";
。。。。
//检索数据库文章的代码。
return m_strRet;
}
对文章进行分页: public string OutputBySize(string p_strContent)
{
int m_intPageSize=1000;//文章每页大小
int m_intCurrentPage = 1;//设置第一页为初始页
int m_intTotalPage = 0;
int m_intArticlelength=p_strContent.Length;//文章长度
if (m_intPageSize < m_intArticlelength)
{//如果每页大小大于文章长度时就不用分页了
if (m_intArticlelength % m_intPageSize == 0)
{//set total pages count
m_intTotalPage = m_intArticlelength / m_intPageSize;
}
else
{//if the totalsize
m_intTotalPage = m_intArticlelength / m_intPageSize + 1;
}
if (Request.QueryString["pages"] != null)
{//set Current page number
try
{//处理不正常的地址栏的值
m_intCurrentPage = Convert.ToInt32(Request.QueryString["pages"]);
if (m_intCurrentPage > m_intTotalPage)
m_intCurrentPage = m_intTotalPage;
}
catch
{
m_intCurrentPage = m_intCurrentPage;
}
}
//set the page content 设置获取当前页的大小
m_intPageSize = m_intCurrentPage < m_intTotalPage ? m_intPageSize : (m_intArticlelength - m_intPageSize * (m_intCurrentPage - 1));
string m_strRet = p_strContent.Substring(m_intPageSize * (m_intCurrentPage - 1), m_intPageSize);
string m_strPageInfo = "<p></p>";
for (int i = 1; i <= m_intTotalPage; i++)
{
if (i == m_intCurrentPage)
m_strPageInfo += "<b>" + i + "</b>|";
else
m_strPageInfo += "<a href=viewArticle.aspx?pages=" + i + ">" + i + "</a>|";
}
//输出显示各个页码
this.labPageNumber.Text = m_strPageInfo;
}
return m_strRet;
}
最后在页面加载事件中调用上面的方法:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string m_strContent = OutputArticle();
this.labContent.Text = OutputBySize(m_strContent);
}
}页面代码很简单为:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ViewArticle.aspx.cs" Inherits="ViewArticle" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="labContent" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="labPageNumber" runat="server"></asp:Label></div>
</form>
</body>
</html>
ilovebm 2009-09-22
  • 打赏
  • 举报
回复
使用LINQ中的Take()和Skip(),试验一下
jy02409187 2009-09-22
  • 打赏
  • 举报
回复
还没解决
jy02409187 2009-09-11
  • 打赏
  • 举报
回复
看到头晕了 有没有简单一点方法啊
又比如这段代码在前台怎么调用啊
public partial class _Default : System.Web.UI.Page
{
private string str;//字符
private int strl;//字符总长度
private int pagesize;//每页显示的字符数
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
str = "1234567891234567898522555";
pagesize = 3;
strl = str.Length;
Response.Write(strl);
substr();
}

private void substr()
{
int ct = Int32.Parse(Request.QueryString["page"]);
if (strl == (strl / pagesize) * pagesize)//看看页面的总记录是否能被每页的记录数整除
{
for (int i = 1; i <= strl / pagesize; i++)
{
Response.Write("页:<a href=t3.aspx?page=" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring(pagesize * ct - pagesize, pagesize);
Response.Write(s);
}
else if (ct * pagesize > strl)//在不被整除的情况下,最后一页的设置,如字符长13,每页3,则处理最后那一页的显示
{
for (int i = 1; i <= (strl / pagesize) + 1; i++)
{
Response.Write("页:<a href=t3.aspx?page=" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring((ct - 1) * pagesize, strl - (ct - 1) * pagesize);
Response.Write(s);

}
else //在不被整除的情况下其他页面的显示设置
{
for (int i = 1; i <= strl / pagesize + 1; i++)
{
Response.Write("页:<a href=Default.aspx?page=" + i + ">" + (i) + "</" + "a>");
}
string s = str.Substring(pagesize * ct - pagesize, pagesize);
Response.Write(s);
}

}
编程有钱人了 2009-09-11
  • 打赏
  • 举报
回复
文章内容为什么放在Repeater 里面? 你想干什么?

j既然是详细页还要Repeater吗
jy02409187 2009-09-11
  • 打赏
  • 举报
回复
刚搜到了一个截取字数的方法 但分页还是没办法
<%# GetContent(DataBinder.Eval(Container.DataItem, "product_jieshao"))%>

protected string GetContent(object product_jieshao){
string s = product_jieshao.ToString();
if(s.length>500) return s.Substring(0,500);
else return s;
}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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