日期:2014-05-18  浏览次数:20447 次

用AspNetPager对搜索结果分页
我没有分了..

请问要怎么实现!!!

------解决方案--------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;

namespace ShowPage
{
/// <summary>
/// Index 的摘要说明。
/// </summary>
public class Index : System.Web.UI.Page
{
protected Wuqi.Webdiyer.AspNetPager pager;
protected System.Web.UI.WebControls.DataGrid dgList;
  
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
string strConn = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection myConnection = new SqlConnection(strConn);
string strsql="Select count(id) from article"; 
SqlCommand myCommand = new SqlCommand(strsql,myConnection);
myCommand.CommandType = CommandType.Text;
SqlDataAdapter myda =new SqlDataAdapter();
myda.SelectCommand = myCommand;
DataSet ds = new DataSet();
myda.Fill(ds,"article");
this.pager.RecordCount=System.Convert.ToInt32(ds.Tables[0].Rows[0][0]); 
BindData(); 
}

}

void BindData() 

string strConn = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection myConnection = new SqlConnection(strConn);
string strsql="Select id,topic from article"; 
SqlCommand myCommand = new SqlCommand(strsql,myConnection);
myCommand.CommandType = CommandType.Text;
SqlDataAdapter myda =new SqlDataAdapter();
myda.SelectCommand = myCommand; 
DataSet ds=new DataSet(); 
myda.Fill(ds,pager.PageSize*(pager.CurrentPageIndex-1),pager.PageSize,"article"); 
this.dgList.DataSource=ds.Tables["article"]; 
this.dgList.DataBind(); 
//动态设置用户自定义文本内容 
pager.CustomInfoText="记录总数:<font color=\"blue\"><b>"+pager.RecordCount.ToString()+"</b></font>"; 
pager.CustomInfoText+=" 总页数:<font color=\"blue\"><b>"+pager.PageCount.ToString()+"</b></font>"; 
pager.CustomInfoText+=" 当前页:<font color=\"red\"><b>"+pager.CurrentPageIndex.ToString()+"</b></font>"; 

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()

this.pager.PageChanged += new Wuqi.Webdiyer.PageChangedEventHandler(this.pager_PageChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void pager_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
pager.CurrentPageIndex=e.NewPageIndex; 
BindData(); 
System.Text.StringBuilder sb=new StringBuilder("<script Language=\"Javascript\"><!--\n");  <