博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自定义控件Pager
阅读量:2730 次
发布时间:2019-05-13

本文共 3209 字,大约阅读时间需要 10 分钟。

using System;

using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Caching;

namespace blackflash{

 /// <summary>
 /// Pager 的摘要说明。
 /// </summary>
 [DefaultProperty("Text"),
  ToolboxData("<{0}:Pager runat=server></{0}:Pager>")]
 public class Pager : Control
 {
  private int maxpage;
  private int page;
  private int per;
  private int total;
  private string url;
   
  [Bindable(true),
   Category("Appearance"),
   DefaultValue("")]

  public Pager()

  {
   this.url = "?";
   this.page = 1;
   this.maxpage = 1;
   this.per = 20;
   this.total = 0;  
  }
  public int MaxPage
  {
   get
   {
    return this.maxpage;
   }
   set
   {
    this.maxpage = value;
   }
  }
  public int PageId
  {
   get
   {
    return this.page;
   }
   set
   {
    this.page = value;
   }
  }
  public int Per
  {
   get
   {
    return this.per;
   }
   set
   {
    this.per = value;
   }
  }
  public int Total
  {
   get
   {
    return this.total;
   }
   set
   {
    this.total = value;
   }
  }
  public string Url
  {
   get
   {
    return this.url;
   }
   set
   {
    this.url = value;
   }
  }
  /// <summary>
  /// 将此控件呈现给指定的输出参数。
  /// </summary>
  /// <param name="output"> 要写出到的 HTML 编写器 </param>
  protected override void Render(HtmlTextWriter output)
  {
   output.Write(this.GetContent());
  }
  /// <summary>
  ///分页数据集返回DataTable数据,分页程序
  /// </summary>
  /// <param name="Table">表名 必须有</param>
  /// <param name="Condition">条件比如:issenderdel=0 可以为空</param>
  /// <param name="Compositor">排序 id desc,可以为空</param>
  /// <param name="Mainkey">主键,必须有</param>
  /// <param name="list">列名,可以为空,空为*,所以列</param>
  /// <returns></returns>
  public DataTable GetData(string Table,string Condition,string Compositor,string Mainkey,string list)
  {
   string SqlStr;
   if (list == "")
   {
    list="*";   
   }
   SqlStr="select count(*) from "+Table;
   if (Condition!="")
   {
    SqlStr+=" where "+Condition;
   }
   this.total=Convert.ToInt32(DataAccess.ExecuteScalar(SqlStr));

   if (total%per==0)

   {
    this.maxpage= total/per;
   }
   else
   {
    this.maxpage= total/per+1;
   }
   if (this.page<1)
   {
    this.page = 1 ;
   }
   else if (page>maxpage)
   {
    this.page = maxpage;
   }
   if (this.page<=1)
   {
    SqlStr="select top " + this.per + " "+list+" from "+Table;
    if (Condition !="")
    {
     SqlStr+=" where "+Condition;
    }
    if (Compositor !="")
    {
     SqlStr+=" order by "+Compositor;
    }
   }
   else
   {
    SqlStr="select top " + this.per + " "+list+" from "+Table+"  where "+Mainkey+" not in (select top " + ((page-1)*per) + " "+Mainkey+" from "+Table;
    if (Condition!="")
    {
     SqlStr+=" where "+Condition;
    }
    if (Compositor !="")
    {
     SqlStr+=" order by "+Compositor;
    }
    if (Condition!="")
    {
     SqlStr+=") and "+Condition;
     if (Compositor !="")
     {
      SqlStr+=" order by "+Compositor;
     }
    }
    else
    {
     SqlStr+=")";
     if (Compositor !="")
     {
      SqlStr+=" order by "+Compositor;
     }
    }
   }
   return DataAccess.dataTable(SqlStr);
  }
  public string GetContent()
  {
    StringBuilder sb = new StringBuilder();
    sb.Append("<script language='javascript'>");
    sb.Append("var s = pager('"+this.url+"total="+this.total+"&',"+ this.page +", "+this.maxpage+"," +this.total+ ","+ this.per+", true);");
    sb.Append("document.write(s);");
    sb.Append("</script>");

   return sb.ToString();

  }

 }

}

转载地址:http://cbptd.baihongyu.com/

你可能感兴趣的文章
group by 与 where, having以及顺序
查看>>
XPath 详解,总结
查看>>
初学XPath,其实很简单
查看>>
要提高SQL查询效率where语句条件的先后次序应如何写
查看>>
jni数据类型及使用
查看>>
JNI对引用数据类型的操作
查看>>
JNI的NIO操作
查看>>
JNI的访问域
查看>>
JNI调用Java方法
查看>>
JNI异常处理
查看>>
JNI日志打印
查看>>
数据结构----哈希表
查看>>
二分查找专题
查看>>
牛客网试题+答案分析+大牛面试经验(2)
查看>>
请你讲述一下互斥锁(mutex)机制,以及互斥锁和读写锁的区别
查看>>
请你回答一下软链接和硬链接区别
查看>>
请你说一说死锁产生的必要条件?
查看>>
你都使用什么线程模型
查看>>
请你来说一说协程
查看>>
请你来手写一下fork调用示例
查看>>