主頁 > 知識庫 > .NET 純分頁代碼實(shí)例

.NET 純分頁代碼實(shí)例

熱門標(biāo)簽:外呼系統(tǒng)費(fèi)用一年 巫師3為什么地圖標(biāo)注的財(cái)寶沒有 寧波自動(dòng)外呼系統(tǒng)代理 怎么給超市做地圖標(biāo)注入駐店 手機(jī)地圖標(biāo)注如何刪除 外呼系統(tǒng)代理品牌 辦理400電話證件 世紀(jì)佳緣地圖標(biāo)注怎么去掉 十堰正規(guī)電銷機(jī)器人系統(tǒng)
前臺
復(fù)制代碼 代碼如下:

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">即將過期賬冊提醒>>/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;width:95%;border-collapse:collapse; text-align:center; font-size: normal">
      tr>
        td style="background-color:#cccccc; font-weight:bold;">賬冊名稱/td>
        td style="background-color:#cccccc; font-weight:bold;">經(jīng)營單位/td>
        td style="background-color:#cccccc; font-weight:bold;color: #FF0000;">距過期天數(shù)/td>
      /tr>
    /HeaderTemplate>
    ItemTemplate>
      tr>
        td>%# DataBinder.Eval(Container.DataItem, "ems_no")%>/td>
        td>%# DataBinder.Eval(Container.DataItem, "TRADE_NAME")%>/td>
        td style="color: #FF0000;">%# DataBinder.Eval(Container.DataItem, "days")%>/td>
      /tr>
    /ItemTemplate>
    %--AlternatingItemTemplate描述交替輸出行的另一種外觀--%>
    AlternatingItemTemplate>
      tr bgcolor="#e8e8e8">
        td>%# DataBinder.Eval(Container.DataItem, "ems_no")%>/td>
        td>%# DataBinder.Eval(Container.DataItem, "TRADE_NAME")%>/td>
        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">首頁/asp:LinkButton>
            asp:LinkButton ID="lbPre" runat="server"  style="color:#0066cc;text-decoration:none; font-size: normal" CommandArgument="P"  OnCommand="lbPage_Command">上頁/asp:LinkButton>
            asp:LinkButton ID="lbNext" runat="server"  style="color:#0066cc;text-decoration:none; font-size: normal" CommandArgument="N"  OnCommand="lbPage_Command">下頁/asp:LinkButton>
            asp:LinkButton ID="lbLast" runat="server"  style="color:#0066cc;text-decoration:none; font-size: normal" CommandArgument="L"  OnCommand="lbPage_Command">末頁/asp:LinkButton>
            nbsp;
            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>

分頁類
復(fù)制代碼 代碼如下:

[Serializable]
    public class Pager
    {
        public int totalRecords;
        public int pageSize;
        public int pageIndex;
        public int totalPages;
    }

后他代碼
復(fù)制代碼 代碼如下:

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);//總記錄數(shù)
            pager.pageSize = 5;//頁大小
            pager.pageIndex = 0;//當(dāng)前頁碼
            if (pager.totalRecords == 0)
            {
                pager.totalPages = 0;
            }
            else
            {
                pager.totalPages = pager.totalRecords / pager.pageSize + (pager.totalRecords % pager.pageSize == 0 ? 0 : 1)-1;//總頁數(shù)
            }
            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, ""/*在此配置排序子句*/, "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();
        //首頁
        if (para == "F") {
            pager.pageIndex = 0;
        }
        //前一頁
        if (para == "P")
        {
            pager.pageIndex = pager.pageIndex-1;
        }
        //下一頁
        if (para == "N")
        {
            pager.pageIndex = pager.pageIndex+1;
        }
        //尾頁
        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) + "頁";
    }
    /// summary>
    /// 綁定文檔
    /// /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('你要下載的文件已經(jīng)不存在!');/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 --- 作為附件下載
        ////inline --- 在線打開
        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);
    }
}
您可能感興趣的文章:
  • asp.net Repeater分頁實(shí)例(PageDataSource的使用)
  • asp.net中使用repeater和PageDataSource搭配實(shí)現(xiàn)分頁代碼
  • Asp.net中使用PageDataSource分頁實(shí)現(xiàn)代碼
  • asp.net利用存儲過程和div+css實(shí)現(xiàn)分頁(類似于博客園首頁分頁)
  • 一個(gè)簡答的Access下的分頁asp.net代碼
  • asp.net 使用ObjectDataSource控件在ASP.NET中實(shí)現(xiàn)Ajax真分頁
  • ASP.NET技巧:access下的分頁方案

標(biāo)簽:泰州 牡丹江 山西 通遼 景德鎮(zhèn) 天門 嘉興

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《.NET 純分頁代碼實(shí)例》,本文關(guān)鍵詞  .NET,純,分頁,代碼,實(shí)例,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《.NET 純分頁代碼實(shí)例》相關(guān)的同類信息!
  • 本頁收集關(guān)于.NET 純分頁代碼實(shí)例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章