zoukankan      html  css  js  c++  java
  • AspNetPager与DataList结合实现分页

    AspNetPager与DataList结合实现分页

    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;

    public partial class Default2 : System.Web.UI.Page
    {
          protected void Page_Load(object sender, EventArgs e)
          {
              Bind();
          }
          private void Bind()
          {
            //将总条数放到分页控件中
              DataTable dt1 = null;
              dt1 = DataCtrl.selecttable("select count(classname) from mess_class","tabnl");
              // this.pager.RecordCount=System.Convert.ToInt32(ds.Tables[0].Rows[0][0]);
              this.AspNetPager1.RecordCount = System.Convert.ToInt32(dt1.Rows[0][0]);
              Bind1();
            
          }
          private void Bind1()
          {
              SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=xuedao;database=zhaoxuedaonet");
              SqlCommand comm = new SqlCommand("select classname from mess_class",conn);
              conn.Open();
              comm.ExecuteNonQuery();

              DataSet ds = new DataSet();
              SqlDataAdapter dapter = new SqlDataAdapter(comm);
              dapter.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex-1),AspNetPager1.PageSize,"table");
              this.DataList1.DataSource = ds.Tables["table"].DefaultView;
              this.DataList1.DataBind();
              //AspNetPager1.CustomInfoText = "记录总数:<font color=\"blue\"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
              //AspNetPager1.CustomInfoText = "总页数:<font color=\"blue\"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
              //AspNetPager1.CustomInfoText = " 当前页:<font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";

              //myda.Fill(ds, pager.PageSize * (pager.CurrentPageIndex - 1), pager.PageSize, "article");
              //this.dgList.DataSource = ds.Tables["article"];
              //this.dgList.DataBind();
              ////动态设置用户自定义文本内容
              //pager.CustomInfoText = "记录总数:<font color=\"blue\"><b>" + pager.RecordCount.ToString() + "</b></font>";
              //pager.CustomInfoText += " 总页数:<font color=\"blue\"><b>" + pager.PageCount.ToString() + "</b></font>";
              //pager.CustomInfoText += " 当前页:<font color=\"red\"><b>" + pager.CurrentPageIndex.ToString() + "</b></font>";


          }
          protected void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
          {
              AspNetPager1.CurrentPageIndex = e.NewPageIndex;
              Bind1();
              //pager.CurrentPageIndex = e.NewPageIndex;
              //BindData();
              //System.Text.StringBuilder sb = new StringBuilder("<script Language=\"Javascript\"><!--\n");
              //sb.Append("var el=document.all;");
              //sb.Append(this.dgList.ClientID);
              //sb.Append(".scrollIntoView(true);");
              //sb.Append("<");
              //sb.Append("/");
              //sb.Append("script>");
              //if (!Page.IsStartupScriptRegistered("scrollScript"))
              //      Page.RegisterStartupScript("scrollScript", sb.ToString());

          }
    }

  • 相关阅读:
    51nod 1254 最大子段和 V2
    51nod 1115 最大M子段和 V3
    51nod 1053 最大M子段和 V2
    51nod 1052 最大M子段和
    51nod 1051 最大子矩阵和
    web.config或App.config中AttachDBFilenamex相对路径问题
    [转帖]unity3D OnTriggerEnter和OnCollisionEnter的一点个人心得(主要讲区别)
    unity3d 第一人称脚本解释MouseLook
    unity3d-游戏实战突出重围,整合游戏
    unity3d-游戏实战突出重围,第四天 添加角色
  • 原文地址:https://www.cnblogs.com/ly5201314/p/1287450.html
Copyright © 2011-2022 走看看