代码解释!专业人士请进!
小弟新手,请多指教,尽量详细,跪谢了!private void Bind_rptList(int ToPage)
{
int CurrentPage = ToPage;
int PageSize = 5;
int PageCount;
int RecordCount;
string PageSQL;
string DataTable = "book";
string DataFiled = "ID";
string DataFileds = "ID,UserName,Face,Sex,QQ,HomePage,Email,IsHidden,Adddate,body,isrely,rebody";
string DataOrders = "ID Desc";
SqlConnection Conn = DB.createdb();
// string connstring = ConfigurationManager.AppSettings["cn"];
// SqlConnection Conn = new SqlConnection();
// Conn.ConnectionString = connstring;
// conn.Open();
Conn.Open();
//* 取得记录总数,计算总页数
SqlCommand cmd = new SqlCommand("Select Count(" + DataFiled + ") From " + DataTable, Conn);
RecordCount = Convert.ToInt32(cmd.ExecuteScalar());
if ((RecordCount % PageSize) != 0)
{
PageCount = RecordCount / PageSize + 1;
}
else
{
PageCount = RecordCount / PageSize;
}
if (ToPage > PageCount)
{
CurrentPage = PageCount;
}
if (CurrentPage <= 1)
{
PageSQL = "Select Top " + PageSize + " " + DataFileds + " From " + DataTable + " Order By " + DataOrders;
}
else
{
PageSQL = "Select Top " + PageSize + " " + DataFileds + " From " + DataTable + " Where " + DataFiled + " Not In ( Select Top " + PageSize * (CurrentPage - 1) + " " + DataFiled + " From " + DataTable + " Order By " + DataOrders + " ) Order By " + DataOrders;
}
SqlDataAdapter oda = new SqlDataAdapter(PageSQL, Conn);
DataSet ds = new DataSet();
oda.Fill(ds, "infList");
this.lbTotalPage.Text = Convert.ToString(PageCount);
this.hlkFirstPage.NavigateUrl = "?ToPage=1";
this.hlkLastPage.NavigateUrl = "?ToPage=" + PageCount;
this.lbCurrentPage.Text = Convert.ToString(CurrentPage);
if (CurrentPage <= 1)
{
this.hlkPrevPage.Enabled = false;
CurrentPage = 1;
}
else
{
this.hlkPrevPage.Enabled = true;
this.hlkPrevPage.NavigateUrl = "?ToPage=" + (ToPage - 1);
}
if (CurrentPage >= PageCount)
{
this.hlkNextPage.Enabled = false;
CurrentPage = PageCount;
}
else
{
this.hlkNextPage.Enabled = true;
this.hlkNextPage.NavigateUrl = "?ToPage=" + (ToPage + 1);
}
rpt1.DataSource = ds.Tables["infList"].DefaultView;
rpt1.DataBind();
Conn.Close();
}