用Repeater做分页遇到点困难 ===数据库控制分页====
我想用数据库的SQL 控制分页功能 要求每页显示4条记录,
可是我不知道怎么写啊
请大侠们帮帮忙 解决怎么分页。
protected void lbtnfirstpage_Click(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
switch (lb.ID.ToString())
{
case "next ":
SqlConnection conn = new SqlConnection( "server=localhost;database=Templit;uid=sa;pwd= '4321 ' ");
str = @ "select top 4 * from message where id not in ( select top 5 id from message order by id desc) order by id asc ";
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(str, conn);
DataSet ds = new DataSet();
da.Fill(ds, "table ");
Repeater1.DataSource = ds.Tables[ "table "].DefaultView;
Repeater1.DataBind();
conn.Close();
break;
case "first ":
conn = new SqlConnection( "server=localhost;database=Templit;uid=sa;pwd= '4321 ' ");
str =@ "select top 2 * from message order by id desc ";
conn.Open();
da = new SqlDataAdapter(str, conn);
ds = new DataSet();
da.Fill(ds, "table ");
Repeater1.DataSource = ds.Tables[ "table "].DefaultView;
Repeater1.DataBind();
conn.Close();
break;
case "p ":
str=@ "select top 3 * from message order by id desc ";
break;
case "l ":
str=@ "select top 3 * from message order by id desc ";
break;
}
下面省略了 上一页 和 末页 的分页代码!
希望各位帮我解决怎么 进行 下一页的 分页
[解决办法]
public static int next=0; //条目数
str = @ "select top 4 * from message where (id not in (select top " + next + " id from message order by id desc))order by id desc ";