| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 446 人关注过本帖
标题:[原创][讨论] DataList分页问题
取消只看楼主 加入收藏
mjxybbl
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-4-1
收藏
 问题点数:0 回复次数:2 
[原创][讨论] DataList分页问题

我用PageDataSource给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();
}

搜索更多相关主题的帖子: DataList 
2007-04-09 14:44
mjxybbl
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-4-1
收藏
得分:0 

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()
现在根本不能实现分页的效果,


2007-04-09 15:14
mjxybbl
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-4-1
收藏
得分:0 

我是通过产品类型ID找到该类型的一系列产品然后绑定Datalist显示内容,最后进行分页,可是Datalist绑定了两次,到底要怎么弄呢


2007-04-09 18:03
快速回复:[原创][讨论] DataList分页问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016649 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved