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());

          }
    }

  • 相关阅读:
    Ubuntu(14.04LTS)学习札记
    【ABAP系列】SAP ABAP解析XML的示例程序
    【ABAP系列】SAP GUI740 PATCH5出现弹窗BUG
    【ABAP系列】SAP 获取工单和工序的状态
    【MM系列】SAP MM中物料帐下修改物料的价格
    【MM系列】SAP 物料帐下修改物料的价格
    【BASIS系列】SAP /usr/sap//DVEBMGS00满了怎么处理
    【MM系列】SAP MM物料账在制品承担差异功能及配置
    【SD系列】SAP 退货冲账过账成本更新
    【ABAP系列】SAP ABAP中使用for all entries in小结
  • 原文地址:https://www.cnblogs.com/ly5201314/p/1287450.html
Copyright © 2011-2022 走看看