可以啊,一样用的void bind(string strClass) { string sql = string.Empty; if(strClass == "NO") sql = "SELECT COUNT(ID) as id from Product"; else sql = "SELECT COUNT(ID) as id from Product WHERE Product_Class = '"+ strClass +"'"; DataTable dt = new DataTable(); DataSet ds = norke.GreatDs(sql); if (ds.Tables[0].Rows.Count > 0) { dt = norke.GreatDs(sql).Tables[0]; this.Label1.Text = " " + dt.Rows[0]["id"].ToString() + " "; pager.RecordCount = Convert.ToInt32(this.Label1.Text); } if (int.Parse(dt.Rows[0]["id"].ToString()) > 0) { string sql1; if (strClass == "NO") sql1 = "select top " + pager.PageSize + " * from Product where id not in (select Top " + (pager.CurrentPageIndex - 1) * pager.PageSize + " id from Product order by id desc) order by id desc"; else sql1 = "select top " + pager.PageSize + " * from Product where id not in (select Top " + (pager.CurrentPageIndex - 1) * pager.PageSize + " id from Product order by id desc) AND Product_class = '" + strClass + "' order by id desc"; DataList1.DataSource = norke.GreatDs(sql1); DataList1.DataBind(); }
{
string sql = string.Empty;
if(strClass == "NO")
sql = "SELECT COUNT(ID) as id from Product";
else
sql = "SELECT COUNT(ID) as id from Product WHERE Product_Class = '"+ strClass +"'";
DataTable dt = new DataTable();
DataSet ds = norke.GreatDs(sql); if (ds.Tables[0].Rows.Count > 0)
{
dt = norke.GreatDs(sql).Tables[0];
this.Label1.Text = " " + dt.Rows[0]["id"].ToString() + " ";
pager.RecordCount = Convert.ToInt32(this.Label1.Text);
} if (int.Parse(dt.Rows[0]["id"].ToString()) > 0)
{
string sql1;
if (strClass == "NO")
sql1 = "select top " + pager.PageSize + " * from Product where id not in (select Top " + (pager.CurrentPageIndex - 1) * pager.PageSize + " id from Product order by id desc) order by id desc";
else
sql1 = "select top " + pager.PageSize + " * from Product where id not in (select Top " + (pager.CurrentPageIndex - 1) * pager.PageSize + " id from Product order by id desc) AND Product_class = '" + strClass + "' order by id desc";
DataList1.DataSource = norke.GreatDs(sql1);
DataList1.DataBind();
}
}pager.RecordCount记录总页数,pager.PageSize每页显示的记录数,pager.CurrentPageIndex当前页数
现在的数据都放在DataSet或IList里面了,现在不能再做什么连接数据库的操作了,就有DataSet或IList 其他的没有,
怎么用AspNetPager控件进行分页
public void GridViewFill()
{
InformationCollection InfoCollection = new InformationCollection();
InformationCollection InfoList = new InformationCollection(); int idCount = MyPaper1.DataSet_StartIndex+MyPaper1.PageSize; for (int i = MyPaper1.DataSet_StartIndex; i < idCount; i++)
{
if (i < InfoCollection.Count)
{
InfoList.Add(InfoCollection[i]);
}
else
{
break;
}
}
GridView1.DataSource = InfoList;
GridView1.DataBind();
}InfoCollection,InfoList都是list集合
InfoCollection 是从数据库中查出的数据
InfoList是要在当前页显示的数据
思路就是从InfoCollection中找出满足条件的添加到InfoList中
{
SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper();
SqlParameter[] ParamList ={
sqlHelper.CreateInParam("@startIndex",SqlDbType.Int,4,nstartIndex),
sqlHelper.CreateInParam("@endIndex",SqlDbType.Int,4,nendIndex),
sqlHelper.CreateInParam("@docount",SqlDbType.Bit,1,0)
};
SqlDataReader rec = null;
try
{
sqlHelper.RunProc("Get_News", ParamList, out rec);
}
catch (Exception ex)
{
SystemError.CreateErrorLog(ex.Message);
throw new Exception(ex.Message, ex);
}
List<News> List_News = new List<News>();
while (rec.Read())
{
News news = new News();
NewClass newClass = new NewClass();
NewClassSQL newClassSQl = new NewClassSQL();
newClass = newClassSQl.Get_SintNewClass(Int32.Parse(rec["ClassID"].ToString()));
news.NewClass = newClass;
news.ID = Int32.Parse(rec["ID"].ToString());
news.Title = rec["Title"].ToString();
news.Source = rec["Source"].ToString();
news.Author = rec["Author"].ToString();
news.Content = rec["Content"].ToString();
news.Updatatime = DateTime.Parse(rec["Updatatime"].ToString());
news.Click = Int32.Parse(rec["Click"].ToString());
List_News.Add(news);
news = null;
newClass = null;
}
return List_News;
}
/// <summary>public partial class News : System.Web.UI.Page
{
int nClassID = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Params["ClassID"] != null)
{
nClassID = Int32.Parse(Request.Params["ClassID"].ToString());
}
if (!Page.IsPostBack)
{
NewsSystem newsSystem = new NewsSystem();
if (nClassID > 0)
{
AspNetPager1.RecordCount = newsSystem.Get_NewsNum(nClassID);
NewClassSystem newClassSystem = new NewClassSystem();
ClassName.Text = ">"+newClassSystem.Get_SintNewClass(nClassID).ClassName;
}
else
{
AspNetPager1.RecordCount = newsSystem.Get_NewsNum();//记录条数
}
}
} protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BinData();
}
public void BinData()
{
NewsSystem newsSystem = new NewsSystem();
if (nClassID > 0)
{
List_News.DataSource = newsSystem.Get_News(AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex,nClassID);//绑定数据
}
else
{
List_News.DataSource = newsSystem.Get_News(AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
}
List_News.DataBind();
}
}
就两个地方