利用DataList控件做的翻页页面怎么利用ajax调用后翻页功能就无效了?
我做的翻页-class.aspx,下面是CS文件里的部分代码:
if(!Page.IsPostBack)
{
CurrentPage=0;
ViewState[ "CurrentPage "]=0;
string sk=SQL_Key;
switch(sk)
{
case "1 ":
sql_sum= "select count(*) as co from products where ( "+Key+ ") and active=0 ";
sql_main= "select * from products where ( "+Key+ ") and active=0 order by ID DESC ";
break;
case "2 ":
sql_sum= "select count(*) as co from products where ( "+Key+ ") and grade=3 and active=0 ";
sql_main= "select * from products where ( "+Key+ ") and grade=3 and active=0 order by ID DESC ";
break;
case "3 ":
sql_sum= "select count(*) as co from products where ( "+Key+ ") and grade=2 and active=0 ";
sql_main= "select * from products where ( "+Key+ ") and grade=2 and active=0 order by ID DESC ";
break;
case "4 ":
sql_sum= "select count(*) as co from products where ( "+Key+ ") and grade=4 and active=0 ";
sql_main= "select * from products where ( "+Key+ ") and grade=4 and active=0 order by ID DESC ";
break;
default:
sql_sum= "select count(*) as co from products where ( "+Key+ ") and active=0 ";
sql_main= "select * from products where ( "+Key+ ") and active=0 order by ID DESC ";
break;
}
//sql_sum= "select count(*) as co from products where category like '% "+Cate_Key+ "% ' ";
ViewState[ "sql_sum "]=sql_sum;
RecordCount=jisuan(sql_sum);
jilushu.Text=RecordCount.ToString();
PageCount=(RecordCount-1-((RecordCount-1)%PageSize))/PageSize+1;
zongyeshu.Text=PageCount.ToString();
ViewState[ "PageCount "]=PageCount;
//sql_main= "select * from products where category like '% "+Cate_Key+ "% ' order by ID DESC ";
ViewState[ "sql_main "]=sql_main;
BindList(sql_main);
}
}
public int jisuan(string key_sum)
{
int shu;
OleDbCommand comm=new OleDbCommand(key_sum,conn);
OleDbDataReader rd=comm.ExecuteReader();
if(rd.Read())
{
shu=Int32.Parse(rd[ "co "].ToString());
}
else
{
shu=0;
}
rd.Close();
return shu;
}
ICollection Create_Source(string sql)
{
int PageIndex;
PageIndex=CurrentPage*PageSize;
OleDbDataAdapter adap=new OleDbDataAdapter(sql,conn);
DataSet ds=new DataSet();
adap.Fill(ds,PageIndex,PageSize, "products ");
return ds.Tables[ "products "].DefaultView;
}
public void BindList(string SQL)
{
dll.DataSource=Create_Source(SQL);
dll.DataBind();
sy.Enabled=true;
xs.Enabled=true;
xx.Enabled=true;
my.Enabled=true;
if(CurrentPage==0)
{
sy.Enabled=false;
xs.Enabled=false;
}
if(CurrentPage==PageCount-1)
{
xx.Enabled=false;
my.Enabled=false;
}
dangqianye.Text=(CurrentPage+1).ToString();
conn.Close();
}
public void Page_OnClick(Object sender,CommandEventArgs e)
{
CurrentPage=(int)ViewState[ "CurrentPage "];
PageCount=(int)ViewState[ "PageCount "];
sql_main=ViewState[ "sql_main "].ToString();
string cmd=e.CommandName;
switch(cmd)
{
case "sy ":
CurrentPage=0;
break;
case "xs ":
CurrentPage--;
break;
case "xx ":
CurrentPage++;
break;
case "my ":
CurrentPage=PageCount-1;
break;
default:
CurrentPage=0;
break;
}
ViewState[ "CurrentPage "]=CurrentPage;
BindList(sql_main);
}
直接带参数浏览class.aspx页的时候能够正常实现翻页,可是我用ajax调用以后就翻不了页了为什么?
var keyid = document.getElementById( "show_productsid_key ").value;
var key = document.getElementById( "show_products_key ").value;
if ((key == null) || (key == " ")) return;
var urlshow = "../iframe/class.aspx?keyID= "+ escape(keyid)+ "&key= "+ escape(key) + "&sql_key=1 ";
xmlHttpshow.open( "GET ", urlshow, true);
xmlHttpshow.onreadystatechange = updatePageshow;
xmlHttpshow.send(null);
请高手指点一下~只有20分了,谢谢~很急~在线等~
[解决办法]
我使用第三方控件。