我用pageDataSuorce在已经绑定的datalist上进行分页可是不能实现,请各位高手指点
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
string id = Request["ProductType"].ToString();
string strSql = "select Goods_Ifon.*,Type_Info.* from Goods_Ifon inner join Type_Info on Goods_Ifon.Goods_typeID=Type_Info.Type_ID where Goods_Ifon.Goods_typeID='" + id + "' ";
SqlCommand Command = CommandBuilder.BuildsqlCommand(strSql);
DataList1.DataSource = Command.ExecuteReader();
DataList1.DataBind();
}
}
public void BindData()
{
DataTable dsTable = new DataTable();
PagedDataSource objPag = new PagedDataSource();//添加分页
objPag.DataSource = dsTable.DefaultView;
objPag.AllowPaging = true;//允许分页
objPag.PageSize = 5;
int curPage;
if (Request.QueryString["Page"] != null)
{
curPage = Int32.Parse(Request.QueryString["Page"]);
}
else
{
curPage = 1;
}
objPag.CurrentPageIndex = curPage - 1;//获取当前页的索引
this.Label1.Text = curPage.ToString();//获取第一页
this.Label2.Text = objPag.PageCount.ToString();//获取总的页
//如果当前也不是首页,设置前一页
if (!objPag.IsFirstPage)
{
HyperLink1.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage - 1);
}
//如果当前的也不是尾页,则设置后页的链接地址
if (!objPag.IsLastPage)
{
HyperLink2.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage + 1);
}
//首页的链接
HyperLink3.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
//尾页的链接
HyperLink4.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + objPag.PageCount.ToString();
DataList1.DataSource = objPag;
DataList1.DataBind();
}
请各位高手帮我看看应该怎样改,不胜感激!