用存储过程使用DataList分页
private void BindBook( string pageindex)
{
string str = ConfigurationManager.ConnectionStrings["Sqlstr"].ConnectionString;
using (SqlConnection sqlcnn = new SqlConnection(str))
{
SqlDataAdapter da = new SqlDataAdapter("book_page", sqlcnn);
da.SelectCommand.Parameters.AddWithValue("@pageIndex",pageindex);
da.SelectCommand.Parameters.Add("@pageCount", SqlDbType.Int).Direction = ParameterDirection.Output;
da.SelectCommand.Parameters.AddWithValue("@pageSize", 5);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
da.Fill(ds);
this.DataList1.DataSource = ds.Tables[0].DefaultView;
this.DataList1.DataBind();
this.HiddenField1.Value = pageindex;
this.HiddenField2.Value=da.SelectCommand.Parameters["@pageCount"].Value.ToString();
this.Label1.Text = pageindex + "/" + this.HiddenField2.Value;
}
}
本文介绍了一种使用存储过程实现DataList分页的方法。通过设置页面索引、每页显示记录数等参数,调用存储过程获取指定页的数据,并更新DataList控件的数据显示。此外,还展示了如何获取总页数并显示当前页码。
100

被折叠的 条评论
为什么被折叠?



