当前位置:编程学习 > C#/ASP.NET >>

一个.net分页测试源码

 
一个.net分页测试源码
作者:淘特网
出处:淘特网
注:转载请注明出处
 <% @ Page Language="C#" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.SqlClient" %>
<Script Language="C#" Runat="Server">
SqlConnection MyConn;
int PageSize,RecordCount,PageCount,CurrentPage;
public void Page_Load(Object src,EventArgs e)
{
 //设定PageSize
 PageSize = 5;
 
 //连接语句
 string MyConnString = "server=127.0.0.1;database=example;uid=sa;pwd=1234567";
 MyConn = new SqlConnection(MyConnString);
 MyConn.Open();
 //第一次请求执行
 if(!Page.IsPostBack)
 {
    ListBind();
    CurrentPage = 0;
    ViewState["PageIndex"] = 0;
    //计算总共有多少记录
    RecordCount = CalculateRecord();
    lblRecordCount.Text = RecordCount.ToString();
    //计算总共有多少页
    PageCount = RecordCount/PageSize;
    lblPageCount.Text = PageCount.ToString();
    ViewState["PageCount"] = PageCount;
 }
}
//计算总共有多少条记录
public int CalculateRecord()
{
 int intCount;
 string strCount = "select count(*) as co from TABLE1";
 SqlCommand MyComm = new SqlCommand(strCount,MyConn);
 SqlDataReader dr = MyComm.ExecuteReader();
补充:asp.net教程,基础入门
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,