| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 508 人关注过本帖
标题:代码解释!专业人士请进!
只看楼主 加入收藏
wandy001
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2009-11-24
结帖率:0
收藏
 问题点数:0 回复次数:0 
代码解释!专业人士请进!
小弟新手,请多指教,尽量详细,跪谢了!
 private void Bind_rptList(int ToPage)
    {
        int CurrentPage = ToPage;
        int PageSize = 5;
        int PageCount;
        int RecordCount;
        string PageSQL;
        string DataTable = "book";
        string DataFiled = "ID";
        string DataFileds = "ID,UserName,Face,Sex,QQ,HomePage,Email,IsHidden,Adddate,body,isrely,rebody";
        string DataOrders = "ID Desc";
        SqlConnection Conn = DB.createdb();
       //  string connstring = ConfigurationManager.AppSettings["cn"];
       // SqlConnection Conn = new SqlConnection();
      //  Conn.ConnectionString = connstring;
      //  conn.Open();
        Conn.Open();
        //* 取得记录总数,计算总页数
        SqlCommand cmd = new SqlCommand("Select Count(" + DataFiled + ") From " + DataTable, Conn);
        RecordCount = Convert.ToInt32(cmd.ExecuteScalar());
        if ((RecordCount % PageSize) != 0)
        {
            PageCount = RecordCount / PageSize + 1;
        }
        else
        {
            PageCount = RecordCount / PageSize;
        }
        if (ToPage > PageCount)
        {
            CurrentPage = PageCount;
        }
        if (CurrentPage <= 1)
        {
            PageSQL = "Select Top " + PageSize + " " + DataFileds + " From " + DataTable + " Order By " + DataOrders;
        }
        else
        {
            PageSQL = "Select Top " + PageSize + " " + DataFileds + " From " + DataTable + " Where " + DataFiled + " Not In ( Select Top " + PageSize * (CurrentPage - 1) + " " + DataFiled + " From " + DataTable + " Order By " + DataOrders + " ) Order By " + DataOrders;
        }
        SqlDataAdapter oda = new SqlDataAdapter(PageSQL, Conn);
        DataSet ds = new DataSet();
        oda.Fill(ds, "infList");
        this.lbTotalPage.Text = Convert.ToString(PageCount);
        this.hlkFirstPage.NavigateUrl = "?ToPage=1";
        this.hlkLastPage.NavigateUrl = "?ToPage=" + PageCount;
        this.lbCurrentPage.Text = Convert.ToString(CurrentPage);
        if (CurrentPage <= 1)
        {
            this.hlkPrevPage.Enabled = false;
            CurrentPage = 1;
        }
        else
        {
            this.hlkPrevPage.Enabled = true;
            this.hlkPrevPage.NavigateUrl = "?ToPage=" + (ToPage - 1);
        }
        if (CurrentPage >= PageCount)
        {
            this.hlkNextPage.Enabled = false;
            CurrentPage = PageCount;
        }
        else
        {
            this.hlkNextPage.Enabled = true;
            this.hlkNextPage.NavigateUrl = "?ToPage=" + (ToPage + 1);
        }
        rpt1.DataSource = ds.Tables["infList"].DefaultView;
        rpt1.DataBind();
        Conn.Close();
    }
搜索更多相关主题的帖子: 代码 专业 解释 
2009-11-24 21:16
快速回复:代码解释!专业人士请进!
数据加载中...
 
   



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

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