您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
ASP.NET结合存储过程写的通用搜索分页程序
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:20:34

存储过程改自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 =

[1] [2] [3] 下一页


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |