亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何編寫.NET 純分頁代碼

發布時間:2021-10-09 11:41:43 來源:億速云 閱讀:99 作者:iii 欄目:開發技術

本篇內容主要講解“如何編寫.NET 純分頁代碼”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“如何編寫.NET 純分頁代碼”吧!

前臺

復制代碼 代碼如下:

<div class="mydiv"   >
             <div >
                   <div ><span >即將過期賬冊提醒>></span></div>
                   <div >
                       <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" >
      <tr>
        <td >賬冊名稱</td>
        <td >經營單位</td>
        <td >距過期天數</td>
      </tr>
    </HeaderTemplate>
    <ItemTemplate>
      <tr>
        <td><%# DataBinder.Eval(Container.DataItem, "ems_no")%></td>
        <td><%# DataBinder.Eval(Container.DataItem, "TRADE_NAME")%></td>
        <td ><%# 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 ><%# DataBinder.Eval(Container.DataItem, "days")%></td>
      </tr>
    </AlternatingItemTemplate>
    <FooterTemplate>
     </table>
    </FooterTemplate>
                       </asp:Repeater>
       <div >
            <asp:LinkButton ID="lbFirst" runat="server"    CommandArgument="F" OnCommand="lbPage_Command">首頁</asp:LinkButton>
            <asp:LinkButton ID="lbPre" runat="server"   CommandArgument="P"  OnCommand="lbPage_Command">上頁</asp:LinkButton>
            <asp:LinkButton ID="lbNext" runat="server"   CommandArgument="N"  OnCommand="lbPage_Command">下頁</asp:LinkButton>
            <asp:LinkButton ID="lbLast" runat="server"   CommandArgument="L"  OnCommand="lbPage_Command">末頁</asp:LinkButton>
            &nbsp;
            <asp:Label ID="lbTip"   runat="server" Text="Label"></asp:Label>
        </div>        
                               </ContentTemplate>
                           </asp:UpdatePanel>
                   </div>
              </div>
             </div>


分頁類

復制代碼 代碼如下:

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


后他代碼

復制代碼 代碼如下:

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);//總記錄數
            pager.pageSize = 5;//頁大小
            pager.pageIndex = 0;//當前頁碼
            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, ""/*在此配置排序子句*/, "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('你要下載的文件已經不存在!');</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);
    }
}

到此,相信大家對“如何編寫.NET 純分頁代碼”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

寻甸| 荆门市| 桦南县| 深圳市| 郁南县| 宿松县| 托克托县| 贞丰县| 沈丘县| 桦南县| 昌黎县| 洱源县| 嘉兴市| 洛隆县| 财经| 尤溪县| 广西| 图片| 阿瓦提县| 如皋市| 五河县| 青州市| 偃师市| 恩施市| 穆棱市| 彰化县| 精河县| 大竹县| 信宜市| 临沭县| 壶关县| 大渡口区| 利津县| 元氏县| 老河口市| 宣化县| 遂溪县| 中西区| 仙游县| 丹巴县| 宁城县|