asp.net 源码保存 用程序分页

源码:


代码如下:

namespace Alex
{
public class PageTools
{
/// <summary>
/// 表名称
/// </summary>
private string tableName;
public string TableName
{
get { return tableName; }
set { tableName = value; }
}
/// <summary>
/// 返回的列名
/// </summary>
private string returnColumns;
public string ReturnColumns
{
get { return returnColumns; }
set { returnColumns = value; }
}
/// <summary>
/// 条件
/// </summary>
private string where;
public string Where
{
get { return where; }
set { where = value; }
}
/// <summary>
/// 排序列
/// </summary>
private string orderColumnName;
public string OrderColumnName
{
get { return orderColumnName; }
set { orderColumnName = value; }
}
/// <summary>
/// 排序,true为降序
/// </summary>
private Boolean orderDesc;
public Boolean OrderDesc
{
get { return orderDesc; }
set { orderDesc = value; }
}
/// <summary>
/// 主键
/// </summary>
private string keyColumnName;
public string KeyColumnName
{
get { return keyColumnName; }
set { keyColumnName = value; }
}
/// <summary>
/// 页面大小
/// </summary>
private Int32 pageSize;
public Int32 PageSize
{
get { return pageSize; }
set { pageSize = value; }
}
/// <summary>
/// 第几页
/// </summary>
private Int32 pageIndex;
public Int32 PageIndex
{
get { return pageIndex; }
set { pageIndex = value; }
}
/// <summary>
/// SQL参数
/// </summary>
private SqlParameter[] whereParams;
public SqlParameter[] WhereParams
{
get { return whereParams; }
set { whereParams = value; }
}
/// <param name="TableName"></param>
/// <param name="ReturnColumns"></param>
/// <param name="Where">条件</param>
/// <param name="OrderColumnName">排序列</param>
/// <param name="OrderDesc">排序,true为降序</param>
/// <param name="KeyColumnName">主键</param>
/// <param name="PageSize">页面大小</param>
/// <param name="PageIndex">第几页</param>
/// <param name="WhereParams">SQL参数</param>
public PageTools(string tableName, string returnColumns, string where, string orderColumnName, Boolean orderDesc,
string keyColumnName, Int32 pageSize, Int32 pageIndex, params SqlParameter[] whereParams)
{
this.TableName = tableName;
this.ReturnColumns = returnColumns;
this.Where = where;
this.OrderColumnName = orderColumnName;
this.OrderDesc = orderDesc;
this.KeyColumnName = keyColumnName;
this.PageSize = pageSize;
this.PageIndex = pageIndex;
this.WhereParams = WhereParams;
}
public PageTools() { }
public DataTable RetrievePagerData()
{
if (pageIndex == 1)
{
return RetrieveTopData();
}
else
{
string sql = string.Format("select top {0} {1} from {2} where {3} and {6} not in ( select top {7} {6} from {2} where {3} order by {4} {5} ) order by {4} {5}", pageSize, returnColumns, tableName, where, orderColumnName, orderDesc == true ? "desc" : string.Empty, keyColumnName, pageSize * (pageIndex - 1));
return DbHelperSQL.Query(sql, CheckNull(whereParams)).Tables[0];
}
}
/// <summary>
/// 获取数据的条数
/// </summary>
/// <param name="TableName"></param>
/// <param name="Where"></param>
/// <param name="WhereParams"></param>
/// <returns></returns>
public Int32 RetrieveDataCount()
{
string sql = string.Format("select count(*) from {0} where {1}" , tableName, where);
Int32 result = (Int32)DbHelperSQL.GetSingle(sql, CheckNull(whereParams));
return result;
}
/// <summary>
/// 获取第一页
/// </summary>
/// <param name="top"></param>
/// <param name="TableName"></param>
/// <param name="ReturnColumns"></param>
/// <param name="Where"></param>
/// <param name="OrderColumnName"></param>
/// <param name="OrderDesc"></param>
/// <param name="WhereParams"></param>
/// <returns></returns>
public DataTable RetrieveTopData()
{
string sql = string.Format("select top {0} {1} from {2} where {3} order by {4} {5}", pageSize, returnColumns, tableName, where, orderColumnName, orderDesc == true ? "desc" : string.Empty);
return DbHelperSQL.Query(sql, whereParams).Tables[0];
}
/// <summary>
/// 移除空参数
/// </summary>
/// <param name="WhereParams"></param>
/// <returns></returns>
private SqlParameter[] CheckNull(SqlParameter[] paras)
{
if (paras == null)
{
return null;
}
List<SqlParameter> list = new List<SqlParameter>();
foreach (SqlParameter para in paras)
{
if (para != null) list.Add(para);
}
return list.ToArray();
}
}
}

页面后台:


代码如下:

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
recordCount = page.RetrieveDataCount();
totalPages = (int)(Math.Ceiling((double)recordCount / (double)page.PageSize));
if (!IsPostBack)
{
BindData();
}
}
Alex.PageTools page = new Alex.PageTools("Test", "*", "1=1", "USER_Account", false, "USER_Account", 10, 1, null);
int recordCount;
public int totalPages;

private void BindData()
{
int pageIndex = SmartGridView1.PageIndex;
if(totalPages>0)
{
if(pageIndex>totalPages-1)
{
pageIndex=totalPages-1;
}
}
else
{
pageIndex=0;
}
SmartGridView1.PageIndex=pageIndex;
page.PageIndex=pageIndex+1;
SmartGridView1.DataSource = page.RetrievePagerData();
SmartGridView1.DataBind();
if (this.SmartGridView1.PageIndex == 0)
{
this.btnFirst.Enabled = false;
this.btnPrev.Enabled = false;
if (totalPages == 1)
{
this.btnLast.Enabled = false;
this.btnNext.Enabled = false;
}
}
else if (this.SmartGridView1.PageIndex == totalPages - 1)
{
this.btnLast.Enabled = false;
this.btnNext.Enabled = false;
}
this.lblpagesum.Text = totalPages.ToString();
this.lblpage.Text = (pageIndex + 1).ToString();
this.lblrowscount.Text = recordCount.ToString();
}
public void NavigateToPage(object sender, CommandEventArgs e)
{
btnFirst.Enabled = true;
btnPrev.Enabled = true;
btnNext.Enabled = true;
btnLast.Enabled = true;
string pageinfo = e.CommandArgument.ToString();
switch (pageinfo)
{
case "Prev":
if (this.SmartGridView1.PageIndex > 0)
{
this.SmartGridView1.PageIndex -= 1;
}
break;
case "Next":
if (this.SmartGridView1.PageIndex < (totalPages - 1))
{
this.SmartGridView1.PageIndex += 1;
}
break;
case "First":
this.SmartGridView1.PageIndex = 0;
break;
case "Last":
this.SmartGridView1.PageIndex = totalPages - 1;
break;
}
if (this.SmartGridView1.PageIndex == 0)
{
btnFirst.Enabled = false;
btnPrev.Enabled = false;
if (totalPages == 1)
{
btnLast.Enabled = false;
btnNext.Enabled = false;
}
}
else if (this.SmartGridView1.PageIndex == totalPages - 1)
{
btnLast.Enabled = false;
btnNext.Enabled = false;
}
BindData();
}
protected void gobtnClick(object sender, EventArgs e)
{
int goPageIndex = Convert.ToInt32(this.goCount.Text.Trim());
if (goPageIndex > 0)
{
if (goPageIndex >= totalPages)
{
this.SmartGridView1.PageIndex = totalPages - 1;
}
else
{
this.SmartGridView1.PageIndex = goPageIndex - 1;
}
}
else if(goPageIndex <=0)
{
this.SmartGridView1.PageIndex = 0;
}
if (this.SmartGridView1.PageIndex == 0)
{
btnFirst.Enabled = false;
btnPrev.Enabled = false;
btnLast.Enabled = true;
btnNext.Enabled = true;
if (totalPages == 1)
{
btnLast.Enabled = false;
btnNext.Enabled = false;
}
}
else if (this.SmartGridView1.PageIndex == totalPages - 1)
{
btnLast.Enabled = false;
btnNext.Enabled = false;
btnFirst.Enabled = true;
btnPrev.Enabled = true;
}
else
{
btnLast.Enabled = true;
btnFirst.Enabled = true;
btnNext.Enabled = true;
btnPrev.Enabled = true;
}
BindData();
}

页面前台:

代码


代码如下:

<%@ Page Language="C#" Theme="msn_blue" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="SmartGridView" Namespace="BOSSWWebUI.SmartGridView" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script type="text/javascript">
function validate() {
var gocount=document.getElementById("goCount").value;
if(gocount=="")
{
alert("请先填写你要导航的页面");
return false;
}
var result;
if(isNaN(gocount))
{
alert("请输入合法的数字");
document.getElementById("goCount").value="";
return false;
}
if(parseInt(gocount)<=0|| parseInt(gocount)><%=this.totalPages %>)
{
alert("数字溢出");
document.getElementById("goCount").value="";
return false;
}
return true;
}
</script>
<form id="form1" runat="server">
<div>
<table cellspacing="0" cellpadding="0" width="98%" align="center" border="0">
<tr id="TrGrid" runat="server">
<td align="left">
○ 页次:<asp:Label ID="lblpage" runat="server" ></asp:Label>/
<asp:Label ID="lblpagesum" runat="server"></asp:Label>,共:<asp:Label
ID="lblrowscount" runat="server"></asp:Label>条</td>
<td align="right">
<asp:LinkButton ID="btnFirst" runat="server" OnCommand="NavigateToPage"
CommandArgument="First" CommandName="Pager" Text="首 页">[首 页]</asp:LinkButton><asp:LinkButton
ID="btnPrev" runat="server" CommandArgument="Prev" OnCommand="NavigateToPage"
CommandName="Pager" Text="上一页">[上一页]</asp:LinkButton><asp:LinkButton ID="btnNext"
runat="server" CommandArgument="Next" OnCommand="NavigateToPage"
CommandName="Pager" Text="下一页">[下一页]</asp:LinkButton><asp:LinkButton ID="btnLast"
runat="server" CommandArgument="Last" OnCommand="NavigateToPage"
CommandName="Pager" Text="尾 页" >[尾 页]</asp:LinkButton>
<asp:TextBox ID=goCount runat="server" Width="50px"></asp:TextBox>
<asp:Button ID="gobtn" runat="server" Text="go" OnClientClick="return validate();" OnClick="gobtnClick" /></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" width="98%" align="center" border="0">
<tr>
<td>
<uc1:SmartGridView ID="SmartGridView1" SkinID="blue" runat="server"
PagingStyle="Default"
CssClassMouseOver="grid_over" EnableViewState="False"
AutoGenerateColumns="False"
Width="100%" currentLanguage="">
<Columns>
<asp:TemplateField>
<headertemplate>
<asp:checkbox id="HeadCheckBox" runat="server" />
</headertemplate>
<itemtemplate>
<asp:checkbox id="checkitem" runat="server" __designer:wfdid="w1"></asp:checkbox>
</itemtemplate>
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" width="5px" cssclass="tdcell" />
</asp:TemplateField>
<asp:BoundField DataField="USER_Account" HeaderText="用户帐号" SortExpression="USER_Account">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_DspName" HeaderText="显示名称" SortExpression="USER_DspName">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_DspEngName" HeaderText="英文名" SortExpression="USER_DspEngName" >
<headerstyle cssclass="tdcell" />
<itemstyle cssclass="tdcell" horizontalalign="Center" />
</asp:BoundField>
<asp:BoundField DataField="USER_HRID" HeaderText="员工号" SortExpression="USER_HRID" >
<headerstyle cssclass="tdcell" />
<itemstyle cssclass="tdcell" horizontalalign="Center" />
</asp:BoundField>
<asp:BoundField DataField="USER_Email" HeaderText="邮件地址" SortExpression="USER_Email">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Title" HeaderText="职 称" SortExpression="USER_Title">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Tel" HeaderText="电 话" SortExpression="USER_Tel">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Active" HeaderText="是否有效" SortExpression="USER_Active">
<headerstyle cssclass="tdcell" />
<itemstyle horizontalalign="Center" cssclass="tdcell" />
</asp:BoundField>
<asp:BoundField DataField="USER_Major" HeaderText="专业" SortExpression="USER_Major" >
<headerstyle cssclass="tdcell" horizontalalign="Center" />
<itemstyle cssclass="tdcell" horizontalalign="Center" />
</asp:BoundField>
</Columns>
<HeaderStyle CssClass="thHead" />
<FixRowCol TableHeight="" TableWidth="" />
<RowStyle CssClass="tdcell" />
</uc1:SmartGridView>
</td></tr>
</table>
</div>
</form>
</body>
</html>

(0)

相关推荐

  • asp.net 源码保存 用程序分页

    源码: 复制代码 代码如下: namespace Alex { public class PageTools { /// <summary> /// 表名称 /// </summary> private string tableName; public string TableName { get { return tableName; } set { tableName = value; } } /// <summary> /// 返回的列名 /// </sum

  • JQuery实现Repeater无刷新批量删除(附后台asp.net源码)

    前台页面 复制代码 代码如下: <head runat="server"> <title>无标题页</title> <script src="Js/jquery-1.5.1.min.js" type="text/javascript"></script> <script src="Js/Demo.js" type="text/javascript&qu

  • 关于oblog、动易、风讯等拥有源码编辑的程序漏洞浅析

    目前的oblog.动易.风讯等一系列著名的系统,都存在源码编辑漏洞. 具体操作是: 1,进入"源码"编辑 2,输入阶段公分四段: 第一段:<此处输入正文,做事需要手下留情嘛,来点实际内容> 第二段:<script>document.write('<div style="display:none">');</script> 第三段:<此处输入作弊链接,获取google的pr值,此处的内容将不会被浏览者看 到,且不会

  • ASP 精华源码收集(五年总结)第1/20页

    <% '#######以下是一个类文件,下面的注解是调用类的方法################################################ '# 注意:如果系统不支持建立Scripting.FileSystemObject对象,那么数据库压缩功能将无法使用 '# Access 数据库类 '# CreateDbFile 建立一个Access 数据库文件 '# CompactDatabase 压缩一个Access 数据库文件 '# 建立对象方法: '# Set a = New

  • 针对163相册的图片可以外连的ASP的源码

    附件是破解的ASP源代码,如果你的空间支持ASP,那么直接传到你空间去就可以了,当然,这里我们为了方便会员,给大家一个统一的就行了! QUOTE: 众所周知,163相册速度是非常快的.简直是QQ相册的好几倍.现在还有个上传工具,可以一次性上传很多张图片. 但是有个很大缺点,就是不能别的地方链接相册里的图片(这个就称为防盗链系统),这个当然是163考虑到自己利益所以才防盗链的. 不过,现在我便要把相册里的图片在论坛显示出来 嘿 下面这张图片,就是我的一张相片,放在163的相册里 QUOTE: 如何

  • java中break和continue源码解析

    在自己学习java语言的过程中,很容易把break和continue的用法混淆.为了便于以后快速查阅及温习,在此特留学习笔记一份. 简述 在任何迭代语句的主体部分,都可以用break和continue控制循环的流程.其中,break用于强行退出循环,不执行循环中剩余的语句.而continue则停止执行当前迭代,然后退回循环起始处,开始下一次迭代. 源码 下面这个程序向大家展示了break和continue在for和while循环中的例子: package com.mufeng.thefourth

  • 一个AJAX自动完成功能的js封装源码[支持中文]第1/2页

    Screenshots screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/u

  • Asp 解析 XML并分页显示源码

    Asp 解析 XML并分页显示,示例源码如下: 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>

  • 一个Asp.Net的显示分页方法 附加实体转换和存储过程 带源码下载

    之前自己一直用Aspnetpager控件来显示项目中的分页,但是每次都要拖一个aspnetpager的控件进去,感觉很不舒服,因为现在自己写的webform都不用服务器控件了,所以自己仿照aspnetpager写了一个精简实用的返回分页显示的html方法,其他话不说了,直接上代码.分页显示信息的实体类: 复制代码 代码如下: public class Pager    {        private string _firstPageText;        /// <summary>   

  • asp.net中Post表单保存页面状态并输出源码的实现方法

    Html页面 复制代码 代码如下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %> <%@ Register Src="UserControl/Ucone.ascx" TagNam

随机推荐