| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 568 人关注过本帖
标题:求DATALIST 分页 急!!该代码没实现分页
只看楼主 加入收藏
wsh
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-4-27
收藏
 问题点数:0 回复次数:0 
求DATALIST 分页 急!!该代码没实现分页
public class addrlist : System.Web.UI.Page
    {  
        int PageSize, RecordCount, PageCount, CurrentPage;
        protected System.Web.UI.WebControls.Label lblCurrentPage;
        protected System.Web.UI.WebControls.Label lblRecordCount;
        protected System.Web.UI.WebControls.Button lbnPrevPage;
        protected System.Web.UI.WebControls.Button lbnNextPage;
        protected System.Web.UI.WebControls.TextBox TextBox1;
        protected System.Web.UI.WebControls.Button Button1;
        protected System.Web.UI.WebControls.DataList DataList1;
        
        protected System.Web.UI.WebControls.DataList dltBoard;
    
        private void Page_Load(object sender, System.EventArgs e)
        {    //设定PageSize
             
            //string strSQL,strC12;
            //int i,j;
            if(Session.Count==0)
                //Page.Response .Write ("hello");
                Page.Response.Redirect("default.aspx");
            else
                if(Session["UserID"].ToString()=="")
                Page.Response.Redirect("default.aspx");
            //strC12=Request["CID"].ToString();
            //第一次请求执行
            if (!Page.IsPostBack)
            {
                ListBind();
                CurrentPage = 0;
                ViewState["PageIndex"] = 0;

                //计算总共有多少记录
                RecordCount = CalculateRecord();
                lblRecordCount.Text=RecordCount.ToString();

                //计算总共有多少页
                PageSize = 3;
                PageCount = RecordCount/PageSize;
            lblCurrentPage.Text =PageCount.ToString();
                ViewState["PageCount"] = PageCount;
            }

public void ListBind()
        {
            //TODO 这个function主要是为了绑定数据
            
            string strC12=Request["CID"].ToString();
            SqlConnection objconn=new SqlConnection(ConfigurationSettings.AppSettings["connstr"]);
            objconn.Open();
            //DataList1.DataSource = CreateSource();
            string strSQL="select * from UserInfo where UserClass LIKE'%"+strC12+"%'";
            SqlDataAdapter da=new SqlDataAdapter(strSQL,objconn);
            DataSet ds=new DataSet();
            da.Fill (ds,"addrlist");
            

            lbnNextPage.Enabled = true;
            lbnPrevPage.Enabled = true;
            if (CurrentPage == (PageCount - 1))
                lbnNextPage.Enabled = false;
            if (CurrentPage == 0)
                lbnPrevPage.Enabled = false;
            lblCurrentPage.Text = (CurrentPage + 1).ToString();
            //DataList1.DataSource =ds.Tables ["addrlist"].DefaultView;
            DataList1.DataBind ();

        }
        //计算总共有多少条记录
        public int CalculateRecord()
        {
            //TODO 这个function主要是得到你要在这个DATALIST中显示的记录的条数
            int intCount;
            string strC12=Request["CID"].ToString();
            SqlConnection objconn=new SqlConnection(ConfigurationSettings.AppSettings["connstr"]);
            objconn.Open();
            string strCount = "select count(*) as co from UserInfo where UserClass LIKE'%"+strC12+"%'";
            SqlCommand objcmd=new SqlCommand(strCount,objconn);
            SqlDataReader dr;
            dr=objcmd.ExecuteReader();
            if (dr.Read())
            {
                intCount = Int32.Parse(dr["co"].ToString());
            }
            else
            {
                intCount = 0;
            }
            dr.Close();
            return intCount;
        }
        protected void lbnNextPage_Click(object sender, EventArgs e)
        {
            //TODO 用来向前翻页
            CurrentPage = (int)ViewState["PageIndex"];
            PageCount = (int)ViewState["PageCount"];

            if (CurrentPage < (PageCount - 1))
                CurrentPage++;

            ViewState["PageIndex"] = CurrentPage;
            ListBind();
        }

        
               
        protected void lbnPrevPage_Click(object sender, EventArgs e)
        {
            //TODO 用来向后翻页
            CurrentPage = (int)ViewState["PageIndex"];
            PageCount = (int)ViewState["PageCount"];

            if (CurrentPage > 0)
                CurrentPage--;

            ViewState["PageIndex"] = CurrentPage;
            ListBind();
        }
搜索更多相关主题的帖子: DATALIST 代码 
2008-05-15 20:22
快速回复:求DATALIST 分页 急!!该代码没实现分页
数据加载中...
 
   



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

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