海量預存程序分頁控制項 Asp.net2.0

來源:互聯網
上載者:User

正常情況下不要用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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.