aspnetpager控件用例

<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

 

 

WebForm1.aspx:
<%@ Register TagPrefix="webdiyer" Namespace="Wuqi.Webdiyer" Assembly="AspNetPager" %>
<TABLE id="Table1" style="HEIGHT: 448px" cellSpacing="0" cellPadding="0" width="550" align="center"
    border="0">
    <TR>
     <TD style="HEIGHT: 35px" align="center" width="150" bgColor="#6699cc"><FONT face="宋体">id</FONT></TD>
     <TD style="HEIGHT: 35px" align="center" width="400" bgColor="#6699cc"><FONT face="宋体">class_name</FONT></TD>
    </TR>
    <TR>
     <TD vAlign="top" align="center" colSpan="2"><asp:datalist id="DL" runat="server" Width="550px" Height="240px">
       <AlternatingItemStyle BackColor="#FFE0C0"></AlternatingItemStyle>
       <ItemTemplate>
        <TABLE id="Table2" cellSpacing="0" cellPadding="0" width="300" border="0">
         <TR>
          <TD align="center" width="150"><%#DataBinder.Eval(Container.DataItem,"ID")%></TD>
          <TD align="center" width="400"><%#DataBinder.Eval(Container.DataItem,"Class_name")%></TD>
         </TR>
        </TABLE>
       </ItemTemplate>
      </asp:datalist></TD>
    </TR>
    <TR>
     <TD align="right" colSpan="2"><webdiyer:aspnetpager id="Pager" runat="server" PageSize="8" ShowCustomInfoSection="Left" PagingButtonSpacing="3px"
       ShowInputBox="Always" SubmitButtonText="转到" PageChanging="Pager_PageChanging"></webdiyer:aspnetpager></TD>
    </TR>
</TABLE>

WebForm1.aspx.cs:
private readonly string SQLCONNECTION =ConfigurationSettings.AppSettings["SQLCONNECTION"];
  private void Page_Load(object sender, System.EventArgs e)
  {
   if(!Page.IsPostBack)
   {
    SqlConnection myconnection = new SqlConnection(SQLCONNECTION);
    string sql ="Select count(*) from Middle_class";
    SqlCommand mycommand = new SqlCommand(sql,myconnection);
    myconnection.Open();
    Pager.RecordCount= Convert.ToInt32(mycommand.ExecuteScalar());
    myconnection.Close();
    BindDL();
   }
  }
  private void BindDL()
  {
   SqlConnection myconnection = new SqlConnection(SQLCONNECTION);
   string sql ="select ID,class_name from Middle_class";
   SqlDataAdapter da = new SqlDataAdapter(sql,myconnection);
   DataSet ds =new DataSet();
   myconnection.Open();
   da.Fill(ds,Pager.PageSize*(Pager.CurrentPageIndex - 1),Pager.PageSize,"middle_class");
   myconnection.Close();
   DL.DataSource =ds;
   DL.DataBind();
   //动态设置用户自定义文本内容
   Pager.CustomInfoHTML ="记录总数:<font color=/"blue/"><b>"+Pager.RecordCount.ToString()+"</b></font>";
   Pager.CustomInfoHTML +=" 总页数:<font color=/"blue/"><b>"+Pager.PageCount.ToString()+"</b></font>";
   Pager.CustomInfoHTML +=" 当前页:<font color=/"red/"><b>"+Pager.CurrentPageIndex.ToString()+"</b></font>";

  }
  

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.Pager.PageChanging += new Wuqi.Webdiyer.PageChangingEventHandler(this.Pager_PageChanging);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  protected void Pager_PageChanging(object src,PageChangingEventArgs e)
  {
   Pager.CurrentPageIndex = e.NewPageIndex;
   BindDL();
  }
  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值