sql语句:SELECT TOP " + pgcount + " * FROM tb_news WHERE new_id >= (select top 1 min(new_id) from (select top " + curPgindex * pgcount + " * from tb_news order by new_time desc) ) ORDER BY new_time asc为什么获取到值了 怎么页面上什么也没有呀??
调试欢乐多
/// 获取新闻列表
/// </summary>
/// <param name="pgcount">每页显示条数</param>
/// <param name="curPgindex">当前页面</param>
/// <returns></returns>
public static DataSet getNewslist(int pgcount,int curPgindex)
{
DataSet ds = new DataSet();
OleDbConnection conn = new OleDbConnection(connStr);
OleDbCommand cmd = new OleDbCommand();
if (curPgindex == 1)
{
cmd.CommandText = "SELECT TOP " + pgcount + " * FROM tb_news order by new_time desc;";
}
else
{
cmd.CommandText = "SELECT TOP " + pgcount + " * FROM tb_news WHERE new_id >= (select top 1 min(new_id) from (select top " + curPgindex * pgcount + " * from tb_news order by new_time desc) ) ORDER BY new_time asc";
}
cmd.Connection = conn;
OleDbDataAdapter oda = new OleDbDataAdapter();
try {
conn.Open();
oda.SelectCommand = cmd;
oda.Fill(ds);
}
catch (Exception ex)
{ throw ex; }
finally { conn.Close(); }
return ds;
} DataSet ds = new DataSet(); ds = DAL.add.getNewslist(4, Convert.ToInt32(this.Label1.Text));
int tcount = DAL.add.getNewsCount();
this.Label3.Text = tcount.ToString();
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 4;
pds.CurrentPageIndex = Convert.ToInt32(Label1.Text) - 1;
if (tcount % 4 == 0) { Label2.Text = (tcount / 4).ToString(); }
else { Label2.Text = ((tcount / 4) + 1).ToString(); } this.DataList1.DataSource = pds;
this.DataList1.DataKeyField = "new_id";
this.DataList1.DataBind();
}
我调试时 数据源里面都有数据的 可为什么页面上却没有显示??
DataSet ds = new DataSet(); ds = DAL.add.getNewslist(4, Convert.ToInt32(this.Label1.Text));
int tcount = DAL.add.getNewsCount();
this.Label3.Text = tcount.ToString();
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 4;
pds.CurrentPageIndex = Convert.ToInt32(Label1.Text) - 1;
if (tcount % 4 == 0) { Label2.Text = (tcount / 4).ToString(); }
else { Label2.Text = ((tcount / 4) + 1).ToString(); } this.DataList1.DataSource = pds;
this.DataList1.DataKeyField = "new_id";
this.DataList1.DataBind();
我看到页面没有数据 就加断点调试了 dataset 和 pds 都有数据 但是页面上却出不来
<ItemTemplate>
<div>
<ul style="margin:0px; padding:0px;">
<li style="line-height:25px; list-style-type:none;">
<asp:HyperLink ID="HyperLink1" runat="server" Font-Size="Small" ToolTip='<%#Eval("new_title") %>' NavigateUrl='<%#Eval("new_staURL") %>' ForeColor="Black">
<%#Eval("new_title") %>
</asp:HyperLink>
</li>
</ul>
</div>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</ItemTemplate>
</asp:DataList>是这样编辑的
呵呵 看一下 你的Label1.Text 是什么值
我的lable1很正常呀 默认是1。点击下一页就变成2了,在点击上一页又变成1.。怎么了 有疑问?
真分页的话就没必要用 PagedDataSource 了吧 把该显示那页的数据全读出来 直接绑定到datalist就行了吧 配合aspnetpager分页读取数据
PageIndex.PageSize = int.Parse(AppConfig.PageSize);
PageIndex.DataSource = NewsDT; NewsList.DataSource = PageIndex.PagedOutDataSource;
NewsList.DataBind();
嘿嘿..不知道你界面的控件的CurrentPageIndex设过值没...
总之先记下了..以后我遇到了也就不怕了.