AspNetPager控件是一个比较好的翻页控件,只需要传入一个参数(总记录数)就可以将数据
绑定到AspNetPager上了.
   翻页时,传入当前页的索引以及每页的记录数就可以了.

下面是一段简单的代码:
if(!Page.IsPostBack)
            
{
                AspNetPager1.RecordCount
=GetRecordCount();
                GetData();
            }

//得到记录总数
        private int GetRecordCount()
        
{
            
string strCon="data source=(local);uid=sa;pwd=sundun;database=lsa1008pt";
            SqlConnection conn
=new SqlConnection(strCon);
            SqlDataAdapter da
=new SqlDataAdapter("select * from users",conn);
            conn.Open();
            DataSet ds
=new DataSet();
            da.Fill(ds);

            
return ds.Tables[0].Rows.Count;

        }

//翻页时绑定数据
        private void GetData()
        
{
            
string strCon="data source=(local);uid=sa;pwd=sundun;database=lsa1008pt";
            SqlConnection conn
=new SqlConnection(strCon);
            SqlCommand com
=new SqlCommand("GetPagedNews",conn);
            com.CommandType
=CommandType.StoredProcedure;
            com.Parameters.Add(
"@pageindex",AspNetPager1.CurrentPageIndex);
            com.Parameters.Add(
"@pagesize",AspNetPager1.PageSize);

            conn.Open();
            DataGrid1.DataSource
=com.ExecuteReader();

            DataGrid1.DataBind();
            conn.Close();

        
        }

//翻页
        private void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
        
{
            AspNetPager1.CurrentPageIndex
=e.NewPageIndex;
                GetData();
        
        }

存储过程:

aspnetpager控件下载
https://files.cnblogs.com/huazi4995/aspnetpager.rar
posted on 2006-10-23 14:46  huazi4995  阅读(977)  评论(1)    收藏  举报