用存储过程使用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;
}
}