首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • GridView用存储过程自定义分页分页的完整例子
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-01-07 11:57:53 楼主
    谁有GridView用存储过程自定义分页分页的完整例子(C#)给一个
    100  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • hongcha99
    • 等级:
    发表于:2008-01-07 12:03:071楼 得分:0
    datalist, repeater 存储过程分页带1,2,3,4,5,6,7导航的
    记住把分都给我哦
    存储过程:直接复制进去
    CREATE proc up_GetTopicList
          @a_TableList Varchar(200),
          @a_TableName Varchar(30),
          @a_SelectWhere Varchar(500),
          @a_SelectOrderId Varchar(20),
          @a_SelectOrder Varchar(50),
          @a_intPageNo int,
          @a_intPageSize int,
          @RecordCount int OUTPUT
    as
      /*定义局部变量*/
      declare @intBeginID        int
      declare @intEndID          int
      declare @intRootRecordCount int
      declare @intRowCount        int
      declare @TmpSelect          NVarchar(600)
      /*关闭计数*/
      set nocount on
     
      /*求总共根贴数*/

      select @TmpSelect = 'set nocount on;select @SPintRootRecordCount = count(*) from '+@a_TableName+' '+@a_SelectWhere
      execute sp_executesql
                @TmpSelect,
                N'@SPintRootRecordCount int OUTPUT',
                @SPintRootRecordCount=@intRootRecordCount OUTPUT

    select @RecordCount = @intRootRecordCount

      if (@intRootRecordCount = 0)    --如果没有贴子,则返回零
          return 0
         
      /*判断页数是否正确*/
      if (@a_intPageNo - 1) * @a_intPageSize > @intRootRecordCount
          return (-1)

      /*求开始rootID*/
      set @intRowCount = (@a_intPageNo - 1) * @a_intPageSize + 1
      /*限制条数*/

      select @TmpSelect = 'set nocount on;set rowcount @SPintRowCount;select @SPintBeginID = '+@a_SelectOrderId+' from '+@a_TableName+' '+@a_SelectWhere+' '+@a_SelectOrder
      execute sp_executesql
                @TmpSelect,
                N'@SPintRowCount int,@SPintBeginID int OUTPUT',
                @SPintRowCount=@intRowCount,@SPintBeginID=@intBeginID OUTPUT


      /*结束rootID*/
      set @intRowCount = @a_intPageNo * @a_intPageSize
      /*限制条数*/

      select @TmpSelect = 'set nocount on;set rowcount @SPintRowCount;select @SPintEndID = '+@a_SelectOrderId+' from '+@a_TableName+' '+@a_SelectWhere+' '+@a_SelectOrder
      execute sp_executesql
                @TmpSelect,
                N'@SPintRowCount int,@SPintEndID int OUTPUT',
                @SPintRowCount=@intRowCount,@SPintEndID=@intEndID OUTPUT


    if @a_SelectWhere='' or @a_SelectWhere IS NULL
      select @TmpSelect = 'set nocount off;set rowcount 0;select '+@a_TableList+' from '+@a_TableName+' where '+@a_SelectOrderId+' between '
    else
      select @TmpSelect = 'set nocount off;set rowcount 0;select '+@a_TableList+' from '+@a_TableName+' '+@a_SelectWhere+' and '+@a_SelectOrderId+' between '

    if @intEndID > @intBeginID
      select @TmpSelect = @TmpSelect+'@SPintBeginID and @SPintEndID'+' '+@a_SelectOrder
    else
      select @TmpSelect = @TmpSelect+'@SPintEndID and @SPintBeginID'+' '+@a_SelectOrder

      execute sp_executesql
                @TmpSelect,
                N'@SPintEndID int,@SPintBeginID int',
                @SPintEndID=@intEndID,@SPintBeginID=@intBeginID

      return(@@rowcount)
      --select @@rowcount
    GO


    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • hongcha99
    • 等级:
    发表于:2008-01-07 12:04:002楼 得分:0
    前台代码
          <table>
          <tr>
            <td>
              <a href="cgalgd.aspx">更多 </a>
            </td>
          </tr>
        <tr>
            <td valign="top" align="left">
                <asp:DataList ID="dl1" runat="server" RepeatColumns="3">
                    <ItemTemplate>
                        <table>
                            <tr>
                                <td>
                                <a href=' <%#DataBinder.Eval(Container.DataItem, "WZ")%>'
                                            style="color: Black" target="_blank">
                                          <img width="100px" height="80px" src=' <%#DataBinder.Eval(Container.DataItem, "LJ")%>' alt="产品图片"/>
                                        </a>
                                        <br />
                                                            <a href=' <%#DataBinder.Eval(Container.DataItem, "WZ")%>'
                                            style="color: Black" target="_blank">
                                <%#strvalue(StripHT(((DataBinder.Eval(Container.DataItem, "JS"))).ToString()),10)%>
                                <%--            <%#strvalue(StripHT(((System.Data.DataRowView)Container.DataItem)["detail"].ToString()), 40)%>--%>
                                        </a>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:DataList>
            </td>
        </tr>
        <tr>
            <td>
                <span class="high" style="display:none;">第 <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>
            </td> 
      </tr>
    </table>
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • hongcha99
    • 等级:
    发表于:2008-01-07 12:04:253楼 得分:0
    后台代码
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Text.RegularExpressions;
    public partial class cpjsq : System.Web.UI.Page
    {
        public int curPage = 1;//当前页
        public int totalPage = 0;//总的页数
        public static string item;
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
                if (Request["item"] != null)
                {
                    item = Request["item"].ToString();
                }
                int intPageNo, intPageSize, intPageCount;
                intPageSize = 6;//OK!!!!!
                if (Request["CurrentPage"] == null)
                {
                    intPageNo = 1;
                }
                else
                {
                    intPageNo = Int32.Parse(Request["CurrentPage"]);
                }
                SqlConnection mySqlConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["BBB"]);
                SqlCommand mySqlCommand = new SqlCommand("up_GetTopicList", mySqlConnection);
                mySqlCommand.CommandType = CommandType.StoredProcedure;

                SqlParameter workParm;
                //newsid,newstitle,newscontent,newsdatetime,newscategory
                //搜索表字段,以","号分隔
                workParm = mySqlCommand.Parameters.Add("@a_TableList", SqlDbType.VarChar, 200);
                mySqlCommand.Parameters["@a_TableList"].Value = "ID,LJ,JS,WZ";

                //搜索表名
                workParm = mySqlCommand.Parameters.Add("@a_TableName", SqlDbType.VarChar, 30);
                mySqlCommand.Parameters["@a_TableName"].Value = "cpjs";

                //搜索条件,如"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 JS like '%" + item + "%'";
                //mySqlCommand.Parameters["@a_SelectWhere"].Value = "where newsid <>'10000000'";


                //表主键字段名,必须为INT类型
                workParm = mySqlCommand.Parameters.Add("@a_SelectOrderId", SqlDbType.VarChar, 50);
                mySqlCommand.Parameters["@a_SelectOrderId"].Value = "ID";

                //排序,可以使用多字段排序但主键字段必需在最前面
                workParm = mySqlCommand.Parameters.Add("@a_SelectOrder", SqlDbType.VarChar, 50);
                mySqlCommand.Parameters["@a_SelectOrder"].Value = "order by ID 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();
                dl1.DataSource = mySqlCommand.ExecuteReader();

                dl1.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();
                if (GetPageCount(intPageSize, RecordCount) != 1)                  //总页数不为1时
                {
                    intPageCount = GetPageCount(intPageSize, RecordCount);

                    LabelPage.Text = intPageCount.ToString();              //lbl总页数

                    HLFistPage.Enabled = true;
                    HLEndPage.Enabled = true;


                    HLFistPage.NavigateUrl = "cpjsq.aspx?CurrentPage=1";                //首页
                    HLEndPage.NavigateUrl = "cpjsq.aspx?CurrentPage=" + intPageCount;    //末页

                    if (intPageNo < intPageCount)                          //传过来的页码小于总页数
                    {
                        HLNextPage.Enabled = true;
                        HLNextPage.NavigateUrl = "cpjsq.aspx?CurrentPage=" + Convert.ToString(intPageNo + 1);    //上一页
                    }
                    else
                    {
                        HLNextPage.Enabled = false;
                        HLEndPage.Enabled = false;
                    }

                    if (intPageNo > 1)                                      //传过来的页码大于1
                    {
                        HLPrevPage.Enabled = true;
                        HLPrevPage.NavigateUrl = "cpjsq.aspx?CurrentPage=" + Convert.ToString(intPageNo - 1);    //下一页
                    }
                    else
                    {
                        HLPrevPage.Enabled = false;
                        HLFistPage.Enabled = false;
                    }
                }
                else
                {
                    HLFistPage.Enabled = false;
                    HLEndPage.Enabled = false;
                    HLNextPage.Enabled = false;
                    HLPrevPage.Enabled = false;
                    //lblAllPage.Text = "1";
                    LabelPage.Text = "1";

                }
                if (this.LabelRecord.Text == "0")
                {
                    Response.Write(" <script>alert('没有搜索到指定的数据!'); </script>");
                }
            }
        }
        public string strvalue(string value, int length)
        {
            if (value.Length > length)
            {
                value = value.Substring(0, length);
                value = value + "...";
                return value;
            }
            else
            {
                return value;
            }
        }
        public string StripHT(string strHtml)
        {
            Regex regex = new Regex(" <.+?>", RegexOptions.IgnoreCase);
            string strOutput = regex.Replace(strHtml, "");
            return strOutput;
        }
        public int GetPageCount(int rowSize, int rowCount)
        {
            int pageCount;  //总页数
            if (rowCount > rowSize)
            {
                if (rowCount % rowSize == 0)
                {
                    pageCount = (rowCount / rowSize);
                }
                else
                {
                    pageCount = (rowCount / rowSize) + 1;
                }
            }
            else
            {
                pageCount = 1;
            }
            return pageCount;
        }
    }
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • hongcha99
    • 等级:
    发表于:2008-01-07 12:05:424楼 得分:0
    你不要看着多就头疼,存储过程直接复制
    前台页和后台把里面的列名改成自己的就可以了,很简单,100%可用

    我好不容易弄出来的,和你一起分享,把分都给我哦,要不然我会伤心的
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • hongcha99
    • 等级:
    发表于:2008-01-07 12:07:365楼 得分:0
    都给我啊
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-01-07 12:26:086楼 得分:0
    问一下啊,存储过程怎么用,放在哪里?
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • hy_lihuan
    • 等级:
    发表于:2008-01-07 12:30:017楼 得分:0
    存储过程呢基本就是上面的,网上很多;
    至于需要绑定什么样的控件无所谓的,要理解它的原理;这样才会方便你自己的二次开发
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • treesky
    • 等级:
    发表于:2008-01-07 12:33:098楼 得分:0
    问一下啊,存储过程怎么用,放在哪里?
    ++++++++++++++++++++++++++++++++++++++++
    //代码是Webmatrix生成的
      public int MyInsertMethodNews(string news_title, string news_content, System.DateTime news_time, int news_type)
        {//增加一条新的文章
            System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionString);
            System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
            dbCommand.CommandType = CommandType.StoredProcedure;
            dbCommand.CommandText = "sp_news_ADD";//存储过程
            dbCommand.Connection = dbConnection;

            System.Data.IDataParameter dbParam_news_title = new System.Data.SqlClient.SqlParameter();
            dbParam_news_title.ParameterName = "@news_title";
            dbParam_news_title.Value = news_title;
            dbParam_news_title.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_news_title);
            System.Data.IDataParameter dbParam_news_content = new System.Data.SqlClient.SqlParameter();
            dbParam_news_content.ParameterName = "@news_content";
            dbParam_news_content.Value = news_content;
            dbParam_news_content.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_news_content);
            System.Data.IDataParameter dbParam_news_time = new System.Data.SqlClient.SqlParameter();
            dbParam_news_time.ParameterName = "@news_time";
            dbParam_news_time.Value = news_time;
            dbParam_news_time.DbType = System.Data.DbType.DateTime;
            dbCommand.Parameters.Add(dbParam_news_time);
            System.Data.IDataParameter dbParam_news_type = new System.Data.SqlClient.SqlParameter();
            dbParam_news_type.ParameterName = "@news_type";
            dbParam_news_type.Value = news_type;
            dbParam_news_type.DbType = System.Data.DbType.Int32;
            dbCommand.Parameters.Add(dbParam_news_type);

            int rowsAffected = 0;
            dbConnection.Open();
            try
            {
                rowsAffected = dbCommand.ExecuteNonQuery();
            }
            finally
            {
                dbConnection.Close();
            }

            return rowsAffected;
        }
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-01-07 12:44:229楼 得分:0
    一楼说存储过程直接复制,复制到哪里啊?
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-01-07 12:47:3310楼 得分:0
    在你的数据库里.

    在查询分析器里执行一下.
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • wdzr_826
    • 等级:
    发表于:2008-01-07 14:00:5211楼 得分:0
    分页存储过程又无数个版本。随便用一个
    分页的时候gridview点页数,然后存储过程pageindex参数设成那页的页数就行很简单的。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-01-07 14:09:5612楼 得分:0
    ^_^
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-13 08:06:5913楼 得分:0
    uo
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-13 08:09:3314楼 得分:0
    学习
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-13 08:30:5615楼 得分:0
    it's good idea~
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-13 08:41:1616楼 得分:0
    aspnetpager 很方便的
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • liuqian4243
    • 等级:
    发表于:2008-05-13 09:17:1117楼 得分:0
    来此认真学习了。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-13 09:20:2618楼 得分:0
    mark
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-13 09:33:1619楼 得分:0
    复制到数据库里!!!


    分都给1楼吧
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-13 10:26:2720楼 得分:0
    学习了
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    世纪乐知(北京)网络技术有限公司 版权所有 京 ICP 证 020026 号
    Copyright © 2000-2007, CSDN.NET, All Rights Reserved