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

我用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();
}
请各位高手帮我看看应该怎样改,不胜感激!

搜索更多相关主题的帖子: datalist 
2007-04-08 13:19
tel1982
Rank: 3Rank: 3
来 自:水星
等 级:新手上路
威 望:8
帖 子:852
专家分:0
注 册:2006-10-21
收藏
得分:0 
以下是引用mjxybbl在2007-4-8 13:19:53的发言:

我用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();
}
请各位高手帮我看看应该怎样改,不胜感激!


Face up to life with smiles no matter what happens
2007-04-08 13:50
tel1982
Rank: 3Rank: 3
来 自:水星
等 级:新手上路
威 望:8
帖 子:852
专家分:0
注 册:2006-10-21
收藏
得分:0 
当然仅供参考。

Face up to life with smiles no matter what happens
2007-04-08 13:51
vilian10
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-3-25
收藏
得分:0 
?????这样就没下文了  ~
 看不懂哦 ·~
2008-06-02 20:45
青格儿
Rank: 4
等 级:贵宾
威 望:11
帖 子:698
专家分:20
注 册:2007-7-31
收藏
得分:0 
呵呵,人家不是说了,要写绑定的表名吗?
要是不理解,去这看看吧,这写的也不错啊。
http://www.
2008-06-03 13:40
hzhy3721
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-6-6
收藏
得分:0 
正使用的自定义控件
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Data.SqlClient;

public partial class pageindex : System.Web.UI.UserControl
{
    //定义接口变量
    private DataView pri_datasour;  //定义数据源
    private int pri_pagesize;       //每页显示项数
    private string pri_link_detail;     //商品详细信息查看链接

    //定义几个属性
    //定义一个DataSource 只写属性
    public DataView datasourse      
    {
        set
        {
            pri_datasour = value;    //利用Value关键字设置属性值
        }
    }

    //定义一个PageSize读写属性
    public int pagesize            
    {
        get
        {
            return pri_pagesize;     //返回属性值
        }
        set
        {
            pri_pagesize = value;     //利用Value关键字设置属性值
        }
    }
    //---------------------------------------------------------------
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            display();
    }
    //------------------------绑定数据,显示结果-----------------------
    private void display()            
    {
        //string strlink;
        PagedDataSource pgds = new PagedDataSource();  //建立PagedDataSource对象,从私有变量中读取有关属性值
        //设置pgds对象实例的相关属性
        pgds.DataSource = pri_datasour;
        pgds.AllowPaging = true;
        pgds.PageSize = pri_pagesize;

        pgds.CurrentPageIndex = Int32.Parse(lblPageIndex.Text);  //设置当前要显示的页面,从隐藏标签中读取
        lblPageCount.Text = pgds.PageCount.ToString();           //获取总页数

        //strlink = link_detail;
        
       // hl_detail.NavigateUrl = pri_link_detail;         //读取链接字符串
        //绑定数据源
        dl_goodslist.DataSource = pgds;
        dl_goodslist.DataBind();

        if (lblPageCount.Text == "0")
            lb_page.Text = "页次:" + pgds.CurrentPageIndex.ToString() + "/" + lblPageCount.Text + "页";
        else
            lb_page.Text = "页次:" + (pgds.CurrentPageIndex.ToString() + 1) + "/" + lblPageCount.Text + "页"; // 页码显示

        //处理当前页为最后一页或第一页时,按钮显示情况
        if (pgds.CurrentPageIndex == (pgds.PageCount - 1))   //当前页为最后一页
        {
            lbt_down.Enabled = false;
            lbt_up.Enabled = true;
        }
        else if (pgds.CurrentPageIndex == 0)             //当前页为第一页
        {
            lbt_up.Enabled = false;
            lbt_down.Enabled = true;
        }
        else
        {
            lbt_up.Enabled = true;
            lbt_down.Enabled = true;
        }
    }

    //--------------------页面索引处理-----------------------
    protected void lbt_click(object sender, CommandEventArgs e)
    {
        int page_index = Int32.Parse(lblPageIndex.Text);   //Int32.Parse()将string类型转换为int型
        int page_count = Int32.Parse(lblPageCount.Text);
        switch ()
        {
            case "first":
                page_index = 0;
                break;
            case "previous":
                if (page_index > 0)
                    page_index -= 1;
                break;
            case "next":
                if (page_index < page_count - 1)
                    page_index += 1;
                break;
            case "last":
                page_index = page_count - 1;
                break;
        }
        lblPageIndex.Text = page_index.ToString();  //将新的显示页码保存到隐藏标签中
        display();
    }

    //--------------------------GO按钮响应---------------------------
    protected void bt_pageindex_Click(object sender, EventArgs e)   
    {
        int page_count = Int32.Parse(lblPageCount.Text);  //获取总页数
        int page_index = Int32.Parse(tb_pageindex.Text);  //获取用户输入的页码
        if (page_index < 1)                               //输入页码小于1,显示首页
            page_index = 0;
        else if (page_index > page_count)                 //输入页码大于总页数,显示尾页
            page_index = page_count - 1;
        else
            page_index = page_index - 1;                  //页码索引从0开始,故减1
        tb_pageindex.Text = "";
        lblPageIndex.Text = page_index.ToString();        //将页码保存到隐藏控件中
        display();                                        //显示所求页面
    }

}
2008-06-06 00:44
hzhy3721
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-6-6
收藏
得分:0 
补充
上面的自定义控件,须在使用的页面中给出参数值,即给自定义控件的接口参数赋值。
2008-06-06 00:48
残影留香
Rank: 1
来 自:广西南宁
等 级:新手上路
帖 子:193
专家分:0
注 册:2008-3-19
收藏
得分:0 
objPag.DataSource = ds.Table[写明邦定的表].DefaultView;
2008-06-06 09:00
快速回复:[求助]怎样用PageDataSource在datalist上分页
数据加载中...
 
   



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

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