最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

.NET 纯分页代码实例

来源:懂视网 责编:小采 时间:2020-11-27 22:40:33
文档

.NET 纯分页代码实例

.NET 纯分页代码实例:前台 代码如下:<div class=mydiv style=width:100%;height:180px;background-color:#f0f7ff> <div style=margin-left:10px;> <div style=background-color:#DAEBFF><
推荐度:
导读.NET 纯分页代码实例:前台 代码如下:<div class=mydiv style=width:100%;height:180px;background-color:#f0f7ff> <div style=margin-left:10px;> <div style=background-color:#DAEBFF><

前台
代码如下:
<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;">经营单位</td>
        <td style="background-color:#cccccc; font-weight:bold;color: #FF0000;">距过期天数</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>
             
            <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>

分页类
代码如下:
[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);
    }
}

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

.NET 纯分页代码实例

.NET 纯分页代码实例:前台 代码如下:<div class=mydiv style=width:100%;height:180px;background-color:#f0f7ff> <div style=margin-left:10px;> <div style=background-color:#DAEBFF><
推荐度:
标签: 代码 例子 示例
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top