?? cases.aspx.cs
字號:
?using System;
using System.Data;
using System.Data.OleDb;
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;
public partial class Cases : System.Web.UI.Page
{
public string Titlep;
public string Descriptionp;
public string Keywordsp;
OleDbConnection MyConn;
int PageSize, RecordCount, PageCount, CurrentPage;
protected void Page_Load(object sender, EventArgs e)
{
//title,des,con
GetContent drt = new GetContent();
OleDbDataReader drf = drt.GetTDC();
while (drf.Read())
{
this.Titlep = drf["Title"].ToString();
this.Descriptionp = drf["Description"].ToString();
this.Keywordsp = drf["Keywords"].ToString();
}
drf.Close();
//設定PageSize
PageSize = 12;
//連接語句
MyConn = DB.CreateDB();
MyConn.Open();
//第一次請求執行
if (!Page.IsPostBack)
{
ListBind();
CurrentPage = 0;
ViewState["PageIndex"] = 0;
//計算總共有多少記錄
RecordCount = CalculateRecord();
//
lblRecordCount.Text = RecordCount.ToString();
//計算總共有多少頁
if (RecordCount % PageSize == 0)
{
PageCount = RecordCount / PageSize;
}
else
{
PageCount = RecordCount / PageSize + 1;
}
lblPageCount.Text = PageCount.ToString();
ViewState["PageCount"] = PageCount;
}
}
//計算總共有多少條記錄
public int CalculateRecord()
{
int intCount;
string strCount = "select count(*) as co from product where pro_name='cases'";
OleDbCommand MyComm = new OleDbCommand(strCount, MyConn);
OleDbDataReader dr = MyComm.ExecuteReader();
if (dr.Read())
{
intCount = Int32.Parse(dr["co"].ToString());
}
else
{
intCount = 0;
}
dr.Close();
return intCount;
}
ICollection CreateSource()
{
int StartIndex;
//設定導入的起終地址
StartIndex = CurrentPage * PageSize;
string strSel = "select * from product where pro_name='cases'";
DataSet ds = new DataSet();
OleDbDataAdapter MyAdapter = new OleDbDataAdapter(strSel, MyConn);
MyAdapter.Fill(ds, StartIndex, PageSize, "pro_name");
return ds.Tables["pro_name"].DefaultView;
}
public void ListBind()
{
DataList1.DataSource = CreateSource();
DataList1.DataBind();
lbnNextPage.Enabled = true;
lbnPrevPage.Enabled = true;
if (CurrentPage == (PageCount - 1)) lbnNextPage.Enabled = false;
if (CurrentPage == 0) lbnPrevPage.Enabled = false;
lblCurrentPage.Text = (CurrentPage + 1).ToString();
}
public void Page_OnClick(Object sender, CommandEventArgs e)
{
CurrentPage = (int)ViewState["PageIndex"];
PageCount = (int)ViewState["PageCount"];
string cmd = e.CommandName;
//判斷cmd,以判定翻頁方向
switch (cmd)
{
case "next":
if (CurrentPage < (PageCount - 1)) CurrentPage++;
break;
case "prev":
if (CurrentPage > 0) CurrentPage--;
break;
}
ViewState["PageIndex"] = CurrentPage;
ListBind();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -