ListView加载图片并分页显示
public void BindDataList(int currentpage)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
pds.AllowPaging = true;//允许分页
pds.PageSize = 6;//每页显示3条数据
pds.CurrentPageIndex = currentpage;//当前页为传入的一个int型值
string strSql = "select A.*,"
+ "(select count(*) from Photo B where B.CategoryID = A.ID) AS p_num,"
+ "(select top 1 C.url from Photo C where C.CategoryID = A.ID) AS url "
+ "from Photo_Category AS A "
+ "where A.C_Status ='公开' "
+ "and A.ID in "
+ "(select CategoryID from Photo)";
conn.Open();//打开数据库连接
SqlDataAdapter sda = new SqlDataAdapter(strSql, conn);
DataSet ds = new DataSet();
sda.Fill(ds);//把执行得到的数据放在数据集中
pds.DataSource = ds.Tables[0].DefaultView;//把数据集中的数据放入分页数据源中
dlPictrue.DataSource = pds;//把数据集中的数据放入分页数据源中
dlPictrue.DataBind();
conn.Close();
}
//分页(略)
public void BindDataList(int currentpage)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
pds.AllowPaging = true;//允许分页
pds.PageSize = 6;//每页显示3条数据
pds.CurrentPageIndex = currentpage;//当前页为传入的一个int型值
string strSql = "select A.*,"
+ "(select count(*) from Photo B where B.CategoryID = A.ID) AS p_num,"
+ "(select top 1 C.url from Photo C where C.CategoryID = A.ID) AS url "
+ "from Photo_Category AS A "
+ "where A.C_Status ='公开' "
+ "and A.ID in "
+ "(select CategoryID from Photo)";
conn.Open();//打开数据库连接
SqlDataAdapter sda = new SqlDataAdapter(strSql, conn);
DataSet ds = new DataSet();
sda.Fill(ds);//把执行得到的数据放在数据集中
pds.DataSource = ds.Tables[0].DefaultView;//把数据集中的数据放入分页数据源中
dlPictrue.DataSource = pds;//把数据集中的数据放入分页数据源中
dlPictrue.DataBind();
conn.Close();
}
//分页(略)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货