求ASP.NET中Repeater分页思路,,不需要不必要的代码,,文字描述即可

 我来答
yueyaquan1221
2011-08-22 · 超过15用户采纳过TA的回答
知道答主
回答量:84
采纳率:0%
帮助的人:61.3万
展开全部
曾经 写过的一个新闻列表页 有分页 ,希望你看后对你有所帮助,有好的方法也可以hi我,互相学习
public partial class news_CategoryNews : BasePage
{
/// <summary>
/// 当前页索引
/// </summary>
/// <remarks>赋负数时会自动赋0</remarks>
private Int32 PageIndex
{

get
{
Object vwIndex = ViewState["PageIndex"];
if (vwIndex == null)
{
int index = 0;
PageIndex = index;
return index;
}
return (Int32)vwIndex;
}
set
{
int index = value;
if (index < 0)
index = 0;

ViewState["PageIndex"] = index;
}
}

StringBuilder conditions = new StringBuilder(" 1=1");//查询条件语句
int pagesize = 20;
/// <summary>
/// 存储总页数
/// </summary>
protected int pageNum
{

get
{
object count = ViewState["count"];
if (count == null)
{
ps.sql_Mamber_neirong("NewsReview", " *", " NewsReview_Id", " NewsReview_Id", PageIndex, pagesize, conditions.ToString(), 1);
ViewState["count"] = ps.pagenum;
return ps.pagenum;
}
return (int)count;
}

}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

object obj_Category_Id = Request.QueryString["Category_Id"];
if (null == obj_Category_Id)
{
Alert("错误参数:Category_Id", "NewsIndex.aspx");
}
//绑定
try
{
conditions.Append(" and NewsInfo_CategoryId = " + Convert.ToInt32(obj_Category_Id) + " ");
BindRpt(0, conditions.ToString());
}
catch (Exception ex)
{
Alert(ex.Message);
}

}
drop_page();
}
//绑定数据
private void BindRpt(int page, string strWhere)
{
try
{
RptNewsInfo.DataSource = ps.sql_Mamber_neirong("NewsInfo", " NewsInfo_Id,NewsInfo_Title,NewsInfo_Summary,NewsInfo_IsLink, NewsInfo_Keywords, NewsInfo_PublishTime, NewsInfo_Author", " NewsInfo_Id", " NewsInfo_Id", page, pagesize, strWhere, 1);
ViewState["count"] = ps.pagenum;
RptNewsInfo.DataBind();

drop_page();
}
catch (Exception ex)
{
Alert(ex.Message);
}

}
#region 分页控件部分
//绑定当前页
protected void drop_page()
{

//如果当前页数等于总记录数-1 ,则禁用下一页按钮否则启用下一页按钮
if (PageIndex == (pageNum - 1))
{
this.LinkButton2.Enabled = false;
}
else
{
this.LinkButton2.Enabled = true;
}

//将页数面板清空,循环添加页数 LinkButton 绑定事件
this.PgPanel.Controls.Clear();

int Step = 5;//移动
int LeftNum = 0;//左
int RightNum = 0;//右

if (PageIndex - Step <1)
{
LeftNum = 0;
}
else
{
LeftNum = PageIndex - Step;
}
if (PageIndex + Step > pageNum)
{
RightNum = pageNum;
}
else
{
RightNum = PageIndex + Step;
}
for (int i = LeftNum; i < RightNum; i++)
{

LinkButton lb = new LinkButton();
if (PageIndex == i)
{
lb.Text = " <font color=red>" + (i + 1).ToString() + " </font>";
}
else
{
lb.Text = " " + (i + 1).ToString() + " ";
}
lb.CommandArgument = i.ToString();
lb.ID = "Bindpage"+i.ToString();
this.PgPanel.Controls.Add(lb);
lb.Click += Bindpage_Click;
}

}
//点击页数激发事件
protected void Bindpage_Click(object sender, EventArgs e)
{
IButtonControl me = sender as IButtonControl;//事件源
PageIndex = Convert.ToInt32(me.CommandArgument);//获取要跳往的页数赋值给PageIndex
//追加查询条件
conditions.Append(" and NewsInfo_CategoryId = " + Convert.ToInt32(Request.QueryString["Category_Id"]) + " ");
BindRpt(PageIndex, conditions.ToString());

}

//下一页
protected void Button2_Click(object sender, EventArgs e)
{

try
{
PageIndex += 1;
conditions.Append(" and NewsInfo_CategoryId = " + Convert.ToInt32(Request.QueryString["Category_Id"]) + " ");
BindRpt(PageIndex, conditions.ToString());

}
catch { }
}
//上一页
protected void Button3_Click(object sender, EventArgs e)
{
try
{
PageIndex -= 1;
conditions.Append(" and NewsInfo_CategoryId = " + Convert.ToInt32(Request.QueryString["Category_Id"]) + " ");
BindRpt(PageIndex, conditions.ToString());
}
catch { }

}
#endregion

}
手机用户23050
2011-08-23 · TA获得超过387个赞
知道答主
回答量:618
采纳率:100%
帮助的人:309万
展开全部
Repeater1.DataSource =(DataSet类型的数据源)
Repeater1.DataBind();
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
vjryh701uzg
2011-08-23 · TA获得超过780个赞
知道小有建树答主
回答量:952
采纳率:0%
帮助的人:548万
展开全部
Repeater1.DataSource =(DataSet类型的数据源)
Repeater1.DataBind();
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式