In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to write .NET Pure pagination Code". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to write .NET pure paging code".
Front Desk
The copy code is as follows:
Reminder that account books are about to expire > >
Name of account book
Operating unit
Days from expiration
Home page
Previous page
Next page
Last page
Paging class
The copy code is as follows:
[Serializable]
Public class Pager
{
Public int totalRecords
Public int pageSize
Public int pageIndex
Public int totalPages
}
After his code
The copy code is as follows:
Using System
Using System.Collections.Generic
Using System.Linq
Using System.Web
Using System.Web.UI
Using System.Web.UI.WebControls
Using InfoSoftGlobal
Using System.Data
Using DCIS.Persistence
Using DCIS.JDXT.Data
Using System.IO
Public partial class COMMON_FirstPage: System.Web.UI.Page
{
DCIS.Web.WebUserInfo CurrentUser = new DCIS.Web.WebUserInfo ()
Protected void Page_Load (object sender, EventArgs e)
{
Pager pager = new Pager ()
CurrentUser = (DCIS.Web.WebUserInfo) Session ["CurrentUser"]
If (! IsPostBack)
{
BindDoc ()
Object o = DBUtil.ExecuteScalarAt ("SQLCOM", "select count (1) from dbo.EMS_PTS_HEAD where DECLARE_CODE='" + CurrentUser.Extends ["AGENT_CODE"] .ToString () + "'and datediff (day,end_Date,getdate ()) between 0 and 7")
Pager.totalRecords = o = = null? 0: Convert.ToInt32 (o); / / Total number of records
Pager.pageSize = 5umbnail / page size
Pager.pageIndex = 0 position / current page number
If (pager.totalRecords = = 0)
{
Pager.totalPages = 0
}
Else
{
Pager.totalPages = pager.totalRecords / pager.pageSize + (pager.totalRecords% pager.pageSize = = 0? 0: 1)-1
}
ViewState ["pager"] = pager
LitChart.Text = CreatChart ()
BindZC (pager.pageIndex, pager.pageSize)
ViewLB (pager)
}
}
Private void bindZC (int pageIndex,int pageSize) {
String strSQL = @ "select EMS_NO,TRADE_NAME,datediff (day,end_Date,getdate ()) DAYS from dbo.EMS_PTS_HEAD where DECLARE_CODE='" + CurrentUser.Extends ["AGENT_CODE"] .ToString () + "'and datediff (day,end_Date,getdate ()) between 0 and 7"
PageSpliter pageSpliter = new PageSpliter (strSQL, "/" / * configure the sort clause here * /, "SQLCOM")
PageSpliter.PageSize = pageSize
StrSQL = pageSpliter.GetPageSQL (pageIndex)
StrSQL + = "order by days"
DataTable dt = DBUtil.FillAt ("SQLCOM", strSQL)
RepZC.DataSource = dt
RepZC.DataBind ()
}
Public void lbPage_Command (object sender, CommandEventArgs e)
{
Pager pager = ViewState ["pager"] as Pager
String para = e.CommandArgument.ToString ()
/ / Home page
If (para = = "F") {
Pager.pageIndex = 0
}
/ / previous page
If (para = = "P")
{
Pager.pageIndex = pager.pageIndex-1
}
/ / next page
If (para = = "N")
{
Pager.pageIndex = pager.pageIndex+1
}
/ / the last page
If (para = = "L")
{
Pager.pageIndex = pager.totalPages
}
BindZC (pager.pageIndex, pager.pageSize)
ViewLB (pager)
ViewState ["pager"] = pager
}
Private void viewLB (Pager pager)
{
LbFirst.Enabled = true
LbLast.Enabled = true
LbPre.Enabled = true
LbNext.Enabled = true
If (pager.totalPages = = 0)
{
LbFirst.Enabled = false
LbLast.Enabled = false
LbPre.Enabled = false
LbNext.Enabled = false
}
If (pager.pageIndex = = 0)
{
LbFirst.Enabled = false
LbPre.Enabled = false
}
If (pager.totalPages = = pager.pageIndex)
{
LbLast.Enabled = false
LbNext.Enabled = false
}
LbTip.Text = pager.pageIndex + 1 + "/" + (pager.totalPages + 1) + "Page"
}
/ / /
/ / bind document
/ / /
Private void BindDoc () {
DataTable dt = DBUtil.FillAt ("SQLCOM", "select * from COM_FileUpload WHERE DESCRIBE='Index'")
RepMD.DataSource = dt
RepMD.DataBind ()
}
Public void DownFile_Command (object sender, CommandEventArgs e)
{
String para = e.CommandArgument.ToString ()
String serverfilpath=Server.MapPath (".. /" + para.Split ('$') [0])
If (! File.Exists (serverfilpath))
{
Page.ClientScript.RegisterStartupScript (GetType (), "", "alert ('the file you want to download no longer exists!')
Return
}
ToDownload (serverfilpath,para.Split ('$') [1])
}
Public static void ToDownload (string serverfilpath, string filename)
{
FileStream fileStream = new FileStream (serverfilpath, FileMode.Open)
Long fileSize = fileStream.Length
HttpContext.Current.Response.ContentType = "application/octet-stream"
HttpContext.Current.Response.AddHeader ("Content-Disposition", "attachment; filename=\"+ UTF_FileName (filename) +"\ ";")
/ attachment-download as an attachment
/ inline-Open online
HttpContext.Current.Response.AddHeader ("Content-Length", fileSize.ToString ())
Byte [] fileBuffer = new byte [fileSize]
FileStream.Read (fileBuffer, 0, (int) fileSize)
HttpContext.Current.Response.BinaryWrite (fileBuffer)
FileStream.Close ()
HttpContext.Current.Response.End ()
}
Private static string UTF_FileName (string filename)
{
Return HttpUtility.UrlEncode (filename, System.Text.Encoding.UTF8)
}
}
At this point, I believe you have a deeper understanding of "how to write .NET pure paging code". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.