分享
 
 
 

ASP.NET结合存储过程写的通用搜索分页程序

王朝asp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

存储过程改自bigeagle的论坛分页程序。请大家批判!:)

select.aspx

---------------------------------------------

<%@ Page Language="C#" %>

<%@ import Namespace="System.Data" %>

<%@ import Namespace="System.Data.SqlClient" %>

<script runat="server">

protected void Page_Load(Object sender, EventArgs e)

{

int intPageNo,intPageSize,intPageCount;

intPageSize = 25;

if (Request["CurrentPage"]==null)

{

intPageNo = 1;

}

else

{

intPageNo = Int32.Parse(Request["CurrentPage"]);

}

SqlConnection mySqlConnection = new SqlConnection("server=(local);Database=test;user id=sa;password=");

SqlCommand mySqlCommand = new SqlCommand("up_GetTopicList", mySqlConnection);

mySqlCommand.CommandType = CommandType.StoredProcedure;

SqlParameter workParm;

//搜索表字段,以","号分隔

workParm = mySqlCommand.Parameters.Add("@a_TableList", SqlDbType.VarChar, 200);

mySqlCommand.Parameters["@a_TableList"].Value = "OFFERID,type,offertime";

//搜索表名

workParm = mySqlCommand.Parameters.Add("@a_TableName", SqlDbType.VarChar, 30);

mySqlCommand.Parameters["@a_TableName"].Value = "offer";

//搜索条件,如"select * from aa where a=1 and b=2 and c=3"则条件为"where a=1 and b=2 and c=3"

workParm = mySqlCommand.Parameters.Add("@a_SelectWhere", SqlDbType.VarChar, 500);

mySqlCommand.Parameters["@a_SelectWhere"].Value = "where type='idl'";

//表主键字段名,必须为INT类型

workParm = mySqlCommand.Parameters.Add("@a_SelectOrderId", SqlDbType.VarChar, 50);

mySqlCommand.Parameters["@a_SelectOrderId"].Value = "offerid";

//排序,可以使用多字段排序但主键字段必需在最前面

workParm = mySqlCommand.Parameters.Add("@a_SelectOrder", SqlDbType.VarChar, 50);

mySqlCommand.Parameters["@a_SelectOrder"].Value = "order by offerid desc";

//页号

workParm = mySqlCommand.Parameters.Add("@a_intPageNo", SqlDbType.Int);

mySqlCommand.Parameters["@a_intPageNo"].Value = intPageNo;

//每页显示数

workParm = mySqlCommand.Parameters.Add("@a_intPageSize", SqlDbType.Int);

mySqlCommand.Parameters["@a_intPageSize"].Value = intPageSize;

//总记录数(存储过程输出参数)

workParm = mySqlCommand.Parameters.Add("@RecordCount", SqlDbType.Int);

workParm.Direction = ParameterDirection.Output;

//当前页记录数(存储过程返回值)

workParm = mySqlCommand.Parameters.Add("RowCount", SqlDbType.Int);

workParm.Direction = ParameterDirection.ReturnValue;

mySqlConnection.Open();

Repeater.DataSource = mySqlCommand.ExecuteReader();

Repeater.DataBind();

mySqlConnection.Close();

Int32 RecordCount = (Int32)mySqlCommand.Parameters["@RecordCount"].Value;

Int32 RowCount = (Int32)mySqlCommand.Parameters["RowCount"].Value;

LabelRecord.Text = RecordCount.ToString();

LabelRow.Text = intPageNo.ToString();

intPageCount = RecordCount/intPageSize;

if ((RecordCount%intPageSize)>0)

intPageCount += 1;

LabelPage.Text = intPageCount.ToString();

if (intPageNo>1)

{

HLFistPage.NavigateUrl = "select.aspx?CurrentPage=1";

HLPrevPage.NavigateUrl = String.Concat("select.aspx?CurrentPage=","",intPageNo-1);

}

else

{

HLFistPage.NavigateUrl = "";

HLPrevPage.NavigateUrl = "";

//HLFistPage.Enabled = false;

//HLPrevPage.Enabled = false;

}

if (intPageNo<intPageCount)

{

HLNextPage.NavigateUrl = String.Concat("select.aspx?CurrentPage=","",intPageNo+1);

HLEndPage.NavigateUrl = String.Concat("select.aspx?CurrentPage=","",intPageCount);

}

else

{

HLNextPage.NavigateUrl = "";

HLEndPage.NavigateUrl = "";

//HLNextPage.Enabled=false;

//HLEndPage.Enabled=false;

}

}

</script>

<html>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<head>

<link href="/style.css" rel="stylesheet" />

<style type="text/css">

.high { font-family: "宋体"; font-size: 9pt; line-height: 140%}

.mid { font-size: 9pt; line-height: 12pt}

.small { font-size: 9pt; line-height: normal}

.TP10_5 {

font-size: 14px;

line-height: 140%;

}

</style>

<style type="text/css">A:link {

COLOR: #cc6666

}

</style>

</head>

<body>

<form runat="server">

<span class="high"> 第<font color="#CC0000"><asp:Label id="LabelRow" runat="server"/></font>页 | 共有<asp:Label id="LabelPage" runat="server"/>页

| <asp:Label id="LabelRecord" runat="server"/>条信息 |

<asp:HyperLink id="HLFistPage" Text="首页" runat="server"/>

| <asp:HyperLink id="HLPrevPage" Text="上一页" runat="server"/>

| <asp:HyperLink id="HLNextPage" Text="下一页" runat="server"/>

| <asp:HyperLink id="HLEndPage" Text="尾页" runat="server"/></span><br>

<asp:Repeater id=Repeater runat="server">

<HeaderTemplate>

<table width="583" border="0" cellspacing="0" cellpadding="0">

<tr>

<td bgcolor="#000000"><table width="100%" border="0" cellpadding="4" cellspacing="1" class="TP10_5">

<tr bgcolor="#999999">

<td align="center"> <strong><font color="#FFFFFF">订单号</font></strong></td>

<td align="center"> <strong><font color="#FFFFFF">服务项目</font></strong></td>

<td align="center"> <strong><font color="#FFFFFF">预订日期</font></strong></td>

<td align="center"> <strong><font color="#FFFFFF">操作人员</font></strong></td>

<td align="center"> <strong><font color="#FFFFFF">分配状态</font></strong></td>

<td> <div align="center"></div></td>

</tr>

</HeaderTemplate>

<ItemTemplate>

<tr align=

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有