Chinaunix首页 | 论坛 | 博客
  • 博客访问: 902655
  • 博文数量: 215
  • 博客积分: 10062
  • 博客等级: 上将
  • 技术积分: 2235
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-01 13:21
文章分类

全部博文(215)

文章存档

2012年(1)

2011年(24)

2009年(16)

2008年(91)

2007年(83)

我的朋友

分类:

2008-01-08 16:39:39

后台代码:
 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.SqlClient;
using BLL;
public partial class usercontrol_second_Janelist : System.Web.UI.UserControl
{
   
    private static String url = ConfigurationSettings.AppSettings["SQLSERVER"];
     private String strSql = "SELECT * From ARTICLELISTVIEW ";
    private String borad_name = "";
    public String Borad_name
    {
        get { return borad_name; }
        set { borad_name = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
       
        ClassCount();
        AMDataBinder();
    }
    protected void ArticlePager_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
    {
        ArticlePager.CurrentPageIndex = e.NewPageIndex;
        AMDataBinder();
    }
    protected void AMDataBinder()
    {
        this.DataList1.DataSource = GetArticleM(strSql, ArticlePager.PageSize * (ArticlePager.CurrentPageIndex - 1), ArticlePager.PageSize);
        this.DataList1.DataBind();
        ArticlePager.CustomInfoText = " 共有文章" + ArticlePager.RecordCount.ToString() + "条";
        ArticlePager.CustomInfoText += " 共有" + ArticlePager.PageCount.ToString() + "页";
        ArticlePager.CustomInfoText += " 当前为第" + ArticlePager.CurrentPageIndex.ToString() + "页";
 
    }

    protected void ClassCount()
    {
        ArticlePager.RecordCount = GetArtcleNum();

      
    }
    ==============================
    读取文章总数
    ==============================
    public int GetArtcleNum()
    {
        String strSql = "SELECT Count(*) From BUMDEARTICLE";
        int ClassNum;
        ClassNum = Convert.ToInt32(ExecuteScalar(strSql).ToString());
        return ClassNum;
    }
    public object ExecuteScalar(string strSql)
    {
        SqlConnection conn = new SqlConnection(url);
        conn.Open();
        SqlCommand cmd = new SqlCommand(strSql, conn);
        object val = cmd.ExecuteScalar();
        conn.Close();
        return val;
    }

    public DataView GetArticleM(string R_CId, int sRecord, int mRecord)
    {
        string strSql="select * from BUMDEARTICLE";
        DataView dv = CreateView(strSql, sRecord, mRecord);
        return dv;
    }
    public DataView CreateView(string strSql, int sRecord, int mRecord)
    {
        SqlConnection con = new SqlConnection(url);
        SqlDataAdapter adapter = new SqlDataAdapter(strSql, con);
        DataSet ds = new DataSet();
        adapter.Fill(ds, sRecord, mRecord, "BUMDEARTICLE");
        DataView dv = ds.Tables["BUMDEARTICLE"].DefaultView;
        con.Close();
        con.Dispose();
        return dv;
    }
}
页面上的引用:
          FirstPageText=" 首页 " LastPageText=" 尾页 " NextPageText=" 下页 " PrevPageText=" 上页 " ShowCustomInfoSection="Left"
        CustomInfoSectionWidth="60%" OnPageChanged="ArticlePager_PageChanged" AlwaysShow="True" CustomInfoTextAlign="Center" NumericButtonCount="20">
  关键的代码
文件: Aspnetpager.rar
大小: 13KB
下载: 下载
 
 
 
阅读(823) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~