日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

简单分页

發(fā)布時間:2023/11/27 生活经验 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 简单分页 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

如果需要考慮如時間的過濾、其他條件的加入,可以在SQL語句進(jìn)行編輯,普通的網(wǎng)站,下面的數(shù)據(jù)瀏覽分頁

就可以了。

aspx代碼:

<%@ Page language="c#" Codebehind="StockOrderFormBrower.aspx.cs" AutoEventWireup="false" Inherits="GSP.StockOrderFormBrower" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>

?<HEAD>
??<title>
???用C#和SQL結(jié)合進(jìn)行數(shù)據(jù)瀏覽分頁
??</title>
??<LINK href="css/main.css" type="text/css" rel="stylesheet">
??<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
??<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
??<meta content="C#" name="CODE_LANGUAGE">
??<meta content="JavaScript" name="vs_defaultClientScript">
?</HEAD>
?
?<body MS_POSITIONING="GridLayout">
??<form id="form1" method="post" runat?="server">
???<table id="ShowData" cellSpacing="0" cellPadding="0" align="center" border="0">
????<%ShowData();%><!--輸出數(shù)據(jù)-->
???</table>
???<table align="right">
????<tr>
?????<td>
??????<%PageLoad_Count();%>
??????<INPUT id="first" type="button" value="? |<? " name="first" runat?="server"><!--第一頁-->
??????<INPUT id="prior" type="button" value="? <? " name="prior" runat?="server"><!--上一頁-->
??????<INPUT id="next" type="button" value="? >? " name="next" runat?="server"><!--下一頁-->
??????<INPUT id="last" type="button" value="? >|? " name="last" runat?="server"><!--最后一頁-->
?????</td>
????</tr>
???</table>
??</form>
?</body>

</HTML>

aspx.cs代碼:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace ASWBLM
{
?/// <summary>
?///?
?/// </summary>
?public class UnionInfo : System.Web.UI.Page
?{???????????????????????????????????
??protected System.Web.UI.HtmlControls.HtmlInputButton first;
??protected System.Web.UI.HtmlControls.HtmlInputButton prior;
??protected System.Web.UI.HtmlControls.HtmlInputButton last;
??protected System.Web.UI.HtmlControls.HtmlInputButton next;


??protected static int CurrentPage = 1;//初始化開始頁面
??protected static int RowCount = 0 ;//本頁有多少條
??private static bool IsPrior = false;//有“前一頁”
??private static bool IsNext = false;//有“下一頁”
??private static bool IsLast = false;//有“最后一頁”
??protected static int not_shown_records=0;//計(jì)算未顯示記錄數(shù)
??private static string startID = "";//設(shè)置上一頁開始ID
??private static string endID = "";//設(shè)置下一頁結(jié)束ID

??private static int page_count = 10;//初始化頁面記錄數(shù)


??private void Page_Load(object sender, System.EventArgs e)
??{???
???// 在此處放置用戶代碼以初始化頁面
???if (!IsPostBack)
???{?????????????
????this.CountRecord().ToString();// 記錄總數(shù)
????this.Page_Count().ToString();//分頁總數(shù)???

????Init_Brower();//初始化瀏覽
???}
??}

??#region Web 窗體設(shè)計(jì)器生成的代碼
??override protected void OnInit(EventArgs e)
??{
???//
???// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計(jì)器所必需的。
???//
???InitializeComponent();
???base.OnInit(e);
??}
??
??/// <summary>
??/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
??/// 此方法的內(nèi)容。
??/// </summary>
??private void InitializeComponent()
??{
???this.first.ServerClick += new System.EventHandler(this.first_ServerClick);
???this.prior.ServerClick += new System.EventHandler(this.prior_ServerClick);
???this.next.ServerClick += new System.EventHandler(this.next_ServerClick);
???this.last.ServerClick += new System.EventHandler(this.last_ServerClick);
???this.Load += new System.EventHandler(this.Page_Load);

??}
??#endregion????????????????
??
???????
??/// <summary>
??/// 顯示數(shù)據(jù)
??/// </summary>
??protected void ShowData()
??{
???DataSet ds = new DataSet();//數(shù)據(jù)集
???ASWBLM.Include.UnionInfo_Provider _uip = new ASWBLM.Include.UnionInfo_Provider();
???string vSQL = "";
???vSQL = GetSQLCommond(vSQL,startID,endID);
???
???ds = _uip.ShowAllUnionInfo(vSQL);//取得全部數(shù)據(jù)的數(shù)據(jù)集

???try
???{?
????Response.Write("<p align=center>");???
????foreach(DataRow dr in ds.Tables["Table"].Rows)
????{?? ????
?????Response.Write("<tr align = center onmouseover = /"this.bgColor = '#cccccc'/" onmouseout = /"this.bgColor='';/">");
?????
?????Response.Write("<td align=/"left/" width=/"60%/"><font color=/"#00309C/">");
?????Response.Write("<a href=/"UnionInfo_Read.aspx?id="+dr["Id"].ToString()+"/" target=/"_self/">");?????
?????Response.Write(dr["Title"].ToString());

?????Response.Write("</a>");
?????Response.Write("</td>");

?????Response.Write("<td align=/"right/">");
?????Response.Write("<font color=/"#999999/">");
?????Response.Write("( "+dr["SummaryDateTime"].ToString()+" )");
?????Response.Write("???? ( 已閱讀"+dr["ReadTimes"].ToString()+"次 )");
?????Response.Write("</font>");
?????Response.Write("</td>");

?????Response.Write("</tr>");
????}????????????????
????Response.Write("</p>");
????startID = ds.Tables["Table"].Rows[0].ItemArray[0].ToString();?????? //通過數(shù)組,取第一個數(shù)據(jù),得到開始號“startID”
????RowCount = ds.Tables["Table"].DefaultView.Count;//得到表的行數(shù)
????endID = ds.Tables["Table"].Rows[RowCount-1].ItemArray[0].ToString();//通過數(shù)組,取最后一個數(shù)據(jù),得到結(jié)束號“endID”
???}
???catch(SqlException e)
???{?????
????Response.Write(e.Message);
???}
??}


??/// <summary>
??/// 計(jì)算未顯示記錄數(shù)
??/// </summary>
??/// <returns></returns>
??protected void NotShownRecords()
??{
???not_shown_records = this.CountRecord()/*查詢總記錄數(shù)*/ - (CurrentPage/*當(dāng)前頁*/ - 1) * page_count/*每頁記錄數(shù)*/;
??}


??/// <summary>
??/// 進(jìn)行輸出信息
??/// </summary>
??protected? void PageLoad_Count()
??{
???this.NotShownRecords();
???Response.Write("總共"+this.CountRecord()+"條記錄?????? ");
???Response.Write("共有"+this.Page_Count()+"頁?????? ");
???Response.Write("第"+CurrentPage.ToString()+"頁?????? ");
???Response.Write("本頁共有"+RowCount.ToString()+"條記錄?????? ");
??}

?

??/// <summary>
??/// 獲得總記錄總數(shù)
??/// </summary>
??/// <returns>時間條件范圍內(nèi)記錄總數(shù)intCount</returns>
??protected int CountRecord()
??{???
???int intCount = 0;
???SqlConnection SqlCon = new SqlConnection(Common._DBConnStr);
???SqlCon.Open ();
???
???//找到條件范圍內(nèi)的記錄總數(shù)
???string strCount = "select count(*) from UnionInfo";
???
???//找到符合條件的第一個記錄
???//string strNum = "select top 1 Id from UnionInfo";

???SqlCommand MyComm = new SqlCommand(strCount,SqlCon);
???SqlDataReader dr = MyComm.ExecuteReader();//讀取數(shù)據(jù)流
???if(dr.Read())
???{
 ?????????????? intCount = Int32.Parse(dr[0].ToString());
???}
???else
???{
 ????????????? intCount = 0;
???}
???dr.Close();
???SqlCon.Close();??????????????
???return intCount;
??}


??/// <summary>
??/// 總分頁數(shù)
??/// </summary>
??/// <returns>分頁總數(shù)</returns>
??protected int Page_Count()
??{
???int pageSum = 0;//分頁總數(shù)???
???pageSum = this.CountRecord() / page_count;?????????? ///記錄總數(shù)/分頁的頁數(shù)
???if ((this.CountRecord() % page_count) > 0) pageSum++;???
???return pageSum;
??}


??/// <summary>
??/// 取得SQL語句
??/// </summary>
??/// <param name="vCmd">返回命令行</param>
??/// <returns></returns>
??private string GetSQLCommond(string vCommond,string startID,string endID)
??{
???this.NotShownRecords();//執(zhí)行未顯示的行

???vCommond = "SELECT TOP "+page_count+"? {0},{1},{2},{3}? FROM [UnionInfo]";
???
???if(IsPrior)//判斷“上一頁”
???{
????
???}
?
???if(IsNext)//判斷“下一頁”
???{

???}

???if (IsLast)//判斷“最后一頁”
???{

???}

???vCommond = string.Format(vCommond,"Id","Title","SummaryDateTime","ReadTimes");//這個是數(shù)據(jù)表的字段
???return vCommond;
??}


??/// <summary>
??/// 輸入按鈕的狀態(tài),進(jìn)行是否可用
??/// </summary>
??/// <param name="first">第一頁的狀態(tài)</param>
??/// <param name="prior">上一頁的狀態(tài)</param>
??/// <param name="next1">下一頁的狀態(tài)</param>
??/// <param name="last">最后一頁的狀態(tài)</param>
??protected void SetButtonState(bool first_,bool prior_,bool next_,bool last_)
??{
???if (CurrentPage==1)//到“第一頁”
???{
????first.Disabled = true;//第一頁狀態(tài)
????prior.Disabled = true;//上一頁狀態(tài)
????next.Disabled = false;?? //下一頁狀態(tài)
????last.Disabled = false; //最后一頁狀態(tài)
???}
???else if (CurrentPage==this.Page_Count())//到“最后一頁”
???{
????first.Disabled = false;//第一頁狀態(tài)
????prior.Disabled = false;//上一頁狀態(tài)
????next.Disabled = true;?? //下一頁狀態(tài)
????last.Disabled = true; //最后一頁狀態(tài)
???}
???else
???{
????first.Disabled = first_;//第一頁狀態(tài)
????prior.Disabled = prior_;//上一頁狀態(tài)
????next.Disabled = next_;?? //下一頁狀態(tài)
????last.Disabled = last_; //最后一頁狀態(tài)
???}
??}

?

??/// <summary>
??/// 第一頁按鈕
??/// </summary>
??/// <param name="sender"></param>
??/// <param name="e"></param>
??private void first_ServerClick(object sender, System.EventArgs e)
??{????????????
???CurrentPage? = 1;
???this.SetButtonState(true,true,false,false);?
???startID = "";
???endID = "";
???RowCount = '0';
???IsLast = false;
???IsPrior = false;
???IsNext = false;
??}


??/// <summary>
??/// 上一頁按鈕
??/// </summary>
??/// <param name="sender"></param>
??/// <param name="e"></param>
??private void prior_ServerClick(object sender, System.EventArgs e)
??{
???if( CurrentPage == 1)//判斷“當(dāng)前頁”是否為1
???{
????this.SetButtonState(true,true,false,false);
???}
???else
???{
????CurrentPage=CurrentPage - 1;//“當(dāng)前頁”自減
????this.SetButtonState(false,false,false,false);
???}
???IsPrior = true;
???IsNext = false;
???IsLast = false;??
??}


??/// <summary>
??/// 最后一頁
??/// </summary>
??/// <param name="sender"></param>
??/// <param name="e"></param>
??private void last_ServerClick(object sender, System.EventArgs e)
??{????????
???CurrentPage=this.Page_Count();//到最后一頁
???this.SetButtonState(false,false,true,true);
???IsLast = true;
???IsPrior = false;
???IsNext = false;
??}


??/// <summary>
??/// 下一頁
??/// </summary>
??/// <param name="sender"></param>
??/// <param name="e"></param>
??private void next_ServerClick(object sender, System.EventArgs e)
??{??????????????????????
???if(CurrentPage == this.Page_Count())//判斷“當(dāng)前頁”是否為“分頁總數(shù)”
???{
????this.SetButtonState(false,false,true,true);
???}
???else
???{
????CurrentPage=CurrentPage + 1;//“當(dāng)前頁”自加
????this.SetButtonState(false,false,false,false);
???}
???IsNext = true;?
???IsLast = false;
???IsPrior = false;
??}


??/// <summary>
??/// 初始瀏覽按鈕
??/// </summary>
??/// <param name="sender"></param>
??/// <param name="e"></param>
??private void Init_Brower()
??{
???CurrentPage = 1;//肯定是從第一頁開始
???if ((CurrentPage == 1) && (this.Page_Count() == 1))
???{
????first.Disabled = true;//第一頁狀態(tài)
????prior.Disabled = true;//上一頁狀態(tài)
????next.Disabled = true;//下一頁狀態(tài)
????last.Disabled = true; //最后一頁狀態(tài)
???}
???else
???{
????first.Disabled = true;//第一頁狀態(tài)
????prior.Disabled = true;//上一頁狀態(tài)
????next.Disabled = false;//下一頁狀態(tài)
????last.Disabled = false; //最后一頁狀態(tài)
???}
???startID = "";//開始號
???endID = "";//結(jié)束號??
???IsLast = false;
???IsPrior = false;
???IsNext = false;
??}
?}
}

?

總結(jié)

以上是生活随笔為你收集整理的简单分页的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。