y_xwx  
公告
  • 昵称:y_xwx
    园龄:3年5个月
    粉丝:0
    关注:0
日历
<2008年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
统计
  • 随笔 - 2
  • 文章 - 0
  • 评论 - 0
  • 引用 - 0

导航

搜索

 
 

常用链接

随笔档案

最新评论

 

正常情况下不要用Gridview自带的分页,执行效率不高,尤其对海量数据进行分页时,需要加载很长时间才能显示。但是,如果我们既想利用Gridview显示数据又要提高数据分页性能怎么办,下面的Asp.net2.0海量存储过程分页控件可以解决你问题。

Asp.net2.0海量存储过程分页控件利用存储过程进行分页,将查询到的结果根据结果的主键或唯一ID进行索引,分页时仅仅是对索引进行分页,而无需加载所有要显示的数据,因此大大提高了性能。

下面介绍一下该控件的使用方法:

1.页面代码

<%@ Register Assembly="ProcdurePagerNet2_0" Namespace="ProcdurePagerNet2_0" TagPrefix="cc1" %>

  <cc1:pager id="pager1" runat="server" oncommand="pager_Command" showfirstlast="true"></cc1:pager>

 

2.cs代码

 

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            pager1.CurrentIndex = 1;
            BindRepeaterAdvance(1);
        }
    }

 

  public void pager_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndx = Convert.ToInt32(e.CommandArgument);
        pager1.CurrentIndex = currnetPageIndx;

        BindRepeaterAdvance(currnetPageIndx);
     }

  private void BindRepeaterAdvance(int pageNo)
    {

 

        SqlConnection cn = new SqlConnection(gloab.getConnString());
        SqlCommand Cmd = new SqlCommand("dbo.GetPaged_News", cn);
        Cmd.CommandType = CommandType.StoredProcedure;
        SqlDataReader dr;

        Cmd.Parameters.Add("@PageSize", SqlDbType.Int, 4).Value = pager1.PageSize;
        Cmd.Parameters.Add("@CurrentPage", SqlDbType.Int, 4).Value = pageNo;
        Cmd.Parameters.Add("@ItemCount", SqlDbType.Int).Direction = ParameterDirection.Output;

        SqlParameter Fname_1 = Cmd.Parameters.Add("@Title", SqlDbType.NVarChar);

        Fname_1.Direction = ParameterDirection.Input;
        Fname_1.Value = txt_Title.Text.Trim();//显示根据标题查询的结果
        cn.Open();
        dr = Cmd.ExecuteReader(CommandBehavior.CloseConnection);

        Grid_News.DataSource = dr;
        Grid_News.DataBind();
        Int32 _totalRecords = Convert.ToInt32(Cmd.Parameters["@ItemCount"].Value);
        pager1.ItemCount = _totalRecords;

        dr.Close();
        cn.Close();
        SqlConnection.ClearPool(cn);

    }

 

演示地址:http://www.mycjweb.com/CJSearch.aspx

需要完整源码和控件的给我发邮件:y.xwx@163.com

posted on 2008-09-10 08:33 y_xwx 阅读(447) 评论(0) 编辑 收藏
 
Copyright © y_xwx Powered by: 博客园 模板提供:沪江博客