. NET Pure Pagination Code Instance _ practical Tips

Source: Internet
Author: User
Front desk
Copy Code code as follows:

<div class= "mydiv" style= "Width:100%;height:180px;background-color: #f0f7ff" >
<div style= "margin-left:10px;" >
<div style= "Background-color: #DAEBFF" ><span style= "font-size:normal; Font-weight:bolder "> Upcoming Overdue Books Reminder >></span></div>
<div style= "margin-left:10px;" >
<asp:scriptmanager id= "ScriptManager1" runat= "Server" >
</asp:ScriptManager>
<asp:updatepanel id= "UpdatePanel1" runat= "Server" >
<ContentTemplate>
<asp:repeater id= "REPZC" runat= "Server" >
<HeaderTemplate>
<table border= "1" cellpadding= "0" cellspacing= "0" style= "color: #0066cc; Text-align:center; Font-size:normal ">
<tr>
&LT;TD style= "Background-color: #cccccc; Font-weight:bold; " > Ledger name </td>
&LT;TD style= "Background-color: #cccccc; Font-weight:bold; " > Business Unit </td>
&LT;TD style= "Background-color: #cccccc; Font-weight:bold;color: #FF0000; " > Distance Expired days </td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval (Container.DataItem, "Ems_no")%></td>
<td><%# DataBinder.Eval (Container.DataItem, "Trade_name")%></td>
&LT;TD style= "color: #FF0000;" ><%# DataBinder.Eval (Container.DataItem, "Days")%></td>
</tr>
</ItemTemplate>
<%--alternatingitemtemplate describes another appearance of alternating output lines--%>
<AlternatingItemTemplate>
<tr bgcolor= "#e8e8e8" >
<td><%# DataBinder.Eval (Container.DataItem, "Ems_no")%></td>
<td><%# DataBinder.Eval (Container.DataItem, "Trade_name")%></td>
&LT;TD style= "color: #FF0000;" ><%# DataBinder.Eval (Container.DataItem, "Days")%></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<div style= "margin-right:10px" >
<asp:linkbutton id= "Lbfirst" runat= "server" style= "color: #0066cc; text-decoration:none; Font-size:normal "commandargument=" F "oncommand=" Lbpage_command "> Home </asp:LinkButton>
<asp:linkbutton id= "Lbpre" runat= "server" style= "color: #0066cc; text-decoration:none; Font-size:normal "commandargument=" P "oncommand=" Lbpage_command "> Prev </asp:LinkButton>
<asp:linkbutton id= "Lbnext" runat= "server" style= "color: #0066cc; text-decoration:none; Font-size:normal "commandargument=" "N" oncommand= "Lbpage_command" > next page </asp:LinkButton>
<asp:linkbutton id= "Lblast" runat= "server" style= "color: #0066cc; text-decoration:none; Font-size:normal "commandargument=" L "oncommand=" Lbpage_command "> Last </asp:LinkButton>

<asp:label id= "Lbtip" style= "color: #0066cc; text-decoration:none; Font-size:normal "runat=" Server "text=" Label ></asp:Label>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>

Paging class
Copy Code code as follows:

[Serializable]
public class Pager
{
public int totalrecords;
public int pageSize;
public int pageIndex;
public int totalpages;
}

After his code
Copy Code code 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 record number
pager.pagesize = 5;//Page size
Pager.pageindex = 0;//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;//Total pages
}
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, ""/* This configuration sort clause * * *, "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
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;
}
Last
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";
}
<summary>
Binding documents
</summary>
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 (), "" "," <script>alert (' You're going to download the file no longer exists! '); </script> ");
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---as Attachment download
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);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.