我写了一段查询的代码,但是不知道如何配合aspnetpager使用?
string sql = "SELECT Document_Deal.Number,Document_Deal.DD_Title,Document_Deal.DD_Content,Document_Deal.DI_Number,Document_Deal.isFP,Document_Deal.isSX,Document_Deal.isHasKeyW,Document_Deal.DD_KeySort,Document_Deal.DD_KeyWords,DOCUMENT_INIT.Doc_InitName FROM Document_Deal LEFT JOIN DOCUMENT_INIT ON DOCUMENT_INIT.Number = Document_Deal.DI_Number WHERE 1=@1 ";//初始的查询语句
SqlParameter spCount = new SqlParameter("@1", 1);//默认SqlParameter
List<SqlParameter> list= new List<SqlParameter>();
list.Add(spCount);
//条件查询
if (dpdKeyGroup.SelectedValue != "全部")
{
sql += " AND Document_Deal.DD_KeySort LIKE @DD_KeySort ";
SqlParameter sp = new SqlParameter("@DD_KeySort",this.dpdIsFP.SelectedValue);
list.Add(sp);
}
//条件查询
if (txtDocSource.Text.Trim() != "")
{
sql += " AND DOCUMENT_INIT.Doc_InitName = @Doc_InitName ";
SqlParameter sp = new SqlParameter("@Doc_InitName", txtDocSource.Text.Trim());
list.Add(sp);
}
//转化成SqlParameter数组
SqlParameter[] sparams = list.ToArray();
this.rpt.DataSource = ErpLib.SqlHelper.Query(sql, sparams);//调用查询方法(用的动软的SQLHELPER类库)
this.rpt.DataBind();
-------------------这样配合AspNetPager要如何实现分页呢?后台怎么写?小鸟实在没有豆,求指点!
要组合成使用top实现分页。参考:http://www.beijibear.com/index.php?aid=385
谢谢,成功了。不过实现的笨拙了一点,是用的您说的那个TOP的
1 string sql = "SELECT TOP " + pageSize + " Document_Deal.Number,Document_Deal.DD_Title,Document_Deal.DD_Content,Document_Deal.DI_Number,Document_Deal.isFP,Document_Deal.isSX,Document_Deal.isHasKeyW,Document_Deal.DD_KeyWSort,Document_Deal.DD_KeyWords,DOCUMENT_INIT.Doc_InitName FROM Document_Deal LEFT JOIN DOCUMENT_INIT ON DOCUMENT_INIT.Number = Document_Deal.DI_Number WHERE Document_Deal.Number NOT IN (SELECT TOP " + pageSize * pageIndex + " Document_Deal.Number FROM Document_Deal ORDER BY Document_Deal.Number DESC ) AND 1=@1 "; 2 3 #region nothing 4 if (dpdPageCount.SelectedValue == "全部") 5 { 6 sql = "SELECT Document_Deal.Number,Document_Deal.DD_Title,Document_Deal.DD_Content,Document_Deal.DI_Number,Document_Deal.isFP,Document_Deal.isSX,Document_Deal.isHasKeyW,Document_Deal.DD_KeyWSort,Document_Deal.DD_KeyWords,DOCUMENT_INIT.Doc_InitName FROM Document_Deal LEFT JOIN DOCUMENT_INIT ON DOCUMENT_INIT.Number = Document_Deal.DI_Number WHERE 1=@1 "; 7 } 8 #endregion 9 10 string sql_count = "SELECT COUNT(*) FROM Document_Deal LEFT JOIN DOCUMENT_INIT ON DOCUMENT_INIT.Number = Document_Deal.DI_Number WHERE 1=@1 "; 11 12 SqlParameter spCount = new SqlParameter("@1", 1); 13 List<SqlParameter> list= new List<SqlParameter>(); 14 list.Add(spCount); 15 16 if (dpdKeyW.SelectedValue != "全部") 17 { 18 sql += " AND Document_Deal.isHasKeyW= @isHasKeyW "; 19 sql_count+=" AND Document_Deal.isHasKeyW= @isHasKeyW "; 20 SqlParameter sp = new SqlParameter("@isHasKeyW", this.dpdKeyW.SelectedValue); 21 list.Add(sp); 22 } 23 24 if (dpdKeyGroup.SelectedValue != "全部") 25 { 26 sql += " AND Document_Deal.DD_KeyWSort LIKE @DD_KeySort "; 27 sql_count += " AND Document_Deal.DD_KeyWSort LIKE @DD_KeySort "; 28 SqlParameter sp = new SqlParameter("@DD_KeySort", this.dpdKeyGroup.SelectedValue); 29 list.Add(sp); 30 } 31 32 sql += " ORDER BY Document_Deal.Number DESC "; 33 SqlParameter[] sparams = list.ToArray(); 34 this.pager.RecordCount= Convert.ToInt32(ErpLib.SqlHelper.GetSingle(sql_count,sparams));//总页数 35 36 this.rpt.DataSource = ErpLib.SqlHelper.Query(sql, sparams); 37 this.rpt.DataBind();
不知道楼主的代码是复制的 还是自己写的 ,建议楼主先根据自己的方法的含义去延伸自己的需求,或者楼主可以直接去AspNetPager官网上看下方法说明,从最简单的调用入手
这是我自己写的。什么叫根据自己的方法去延伸自己的需求,还是根据自己的需求去延伸自己的方法。
AspNetPager我是用过的,只是没有参数化,只是绑定了一个列表,我在试1L的办法,有点效果了