<%--左文章--%>
<div class="ifUeTopNews">
<ul class="ifNewsList">
<asp:Repeater runat="server" ID="dlList">
<ItemTemplate>
<li><em></em><a href=''><%# Eval("Title") %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
<%--右文章列表--%>
<div class="ifUeNewsList">
<ul class="ifNewsList">
<asp:Repeater runat="server" ID="dlListTopd">
<ItemTemplate>
<li><em></em><a href=''><%# Eval("Title") %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
</div>
</div>
使用AspNetPager控件进行分页....
如何实现呢?给个思路....
编辑器加载中...
解决思路如下:
1.对数据库进行分页语句的查询。
2.对AspNetPager设置总记录数。
3.使用PagedDataSource设置相关属性,如分页数、当前索引、设置把数据集等...
4.创建并设置2个DataView
5.通过条件判断来进行2个DataView的数据的填充
6.把2个Dataview对象设置到相应的数据源绑定即可
Code:
public void BindData(int index)
{
string sql = @"select top (" + AspNetPager1.PageSize + @") * from Article where ArticleTypeID=7 and id not in (
select top (" + AspNetPager1.PageSize + @"*" + (index - 1) + @") id from SH_Article where ArticleTypeID=7 order by CreateTime desc
) order by CreateTime desc";
DataTable ents = Iwoak.ExecSQL.ExecuteDataTable(sql);
this.AspNetPager1.RecordCount = Convert.ToInt32(Iwoak.ExecSQL.ExecuteScalar("select Count(*) from Article where ArticleTypeID=7").ToString());
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = index - 1;
pds.DataSource = ents.DefaultView;
DataView dv = (DataView)pds.DataSource;
DataView dv2 = null;
if (dv.Count >= 7)
{
DataTable dts = dv.Table.Clone();//拷贝表结构
DataRow[] drs = dv.Table.Select();
DataTable dts2 = dv.Table.Clone();
for (int i = 0; i < drs.Length; i++)
{
if (i >= 7)
{
dts2.Rows.Add(drs[i].ItemArray);//若此处使用dts2.Rows.Add(drs[i]);//出错提示为:该行已经属于另一个表
}
else
{
dts.Rows.Add(drs[i].ItemArray);
}
}
dv = dts.DefaultView;//若此处使用dv.Table=dts;//错处提示为:不能对DataView中的Table进行处理。
dv2 = dts2.DefaultView;
}
dlList.DataSource = dv;
dlList.DataBind();
dlListTopd.DataSource = dv2;
dlListTopd.DataBind();
}