Today I have nothing to worry about. in C #2.0, I used ajax to write an example of refreshing and fast paging. The time is too short. For the shortcomings, please point out that we should first put ajaxpro. DLL file to reference, you can go to http://www.schwarz-interactive.de/download according to your.. Net to select different DLL files. default. aspx. CS: public partial class _ default: system. web. UI. page { String connectstring = ""; // define your own connection string Protected void page_load (Object sender, eventargs E) { Ajaxpro. Utility. registertypeforajax (typeof (_ default )); } [Ajaxpro. ajaxmethod] Public datatable getdatatable () { Sqldataadapter ad = new sqldataadapter ("select * From tablename", connectstring ); Dataset DS = new dataset (); Ad. Fill (DS ); Int num = Ds. Tables [0]. Rows. count; Return Ds. Tables [0]; }} |
Default. aspx: <% @ page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Ajax refreshing pagination </title>
<Script language = "JavaScript">
VaR dtobj = new object ();
Function stringtointeger (inputstring)
{
If (inputstring = NULL | inputstring = "")
{
Return 0;
}
Else
{
Try
{
Return parseint (inputstring );
}
Catch (E)
{
Return 0;
}
}
}
Function numbertostring (inputnumber)
{
Return inputnumber. tostring ();
}
Function geturlparam (PARAM)
{
VaR url = Window. Location. Search. substring (1 );
VaR paramarray = URL. Split ("&");
For (VAR I = 0; I <paramarray. length; I ++)
{
VaR pramarraysub = paramarray [I]. Split ("= ");
If (pramarraysub [0] = Param & pramarraysub [1]! = "Undefined ")
Return pramarraysub [1];
}
Return "";
}
VaR pagesize = 5;
// Var pageno = stringtointeger (geturlparam ("pageno "));
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div align = center> <span id = "sp_showcontent"> </span> </div>
</Form>
</Body>
</Html>
<Script language = JavaScript>
VaR pageno = 0;
VaR dtobj = new object (); // Object Instantiation ***************
Dtobj = _ default. getdatatable (). value; // obtain data from the background **********
VaR totalpage = 0;
VaR totalrecord = dtobj. Rows. length;
If (dtobj. Rows. Length % pagesize) = 0)
Totalpage = dtobj. Rows. Length/pagesize;
Else
Totalpage = math. Ceil (dtobj. Rows. Length/pagesize );
Function showcontent (OP)
{
If (OP = "first ")
{
Pageno = 0;
}
Else if (OP = "previous ")
{
If (pageno> 0)
Pageno-= 1;
Else
Pageno = 0;
}
Else if (OP = "Next ")
{
If (pageno <totalPage-1)
Pageno + = 1;
Else
Pageno = totalPage-1;
}
Else if (OP = "last ")
{
Pageno = totalPage-1;
}
Else
{
Pageno = 0;
}
VaR content = "";
VaR startrecord = pageno * pagesize;
VaR endrecord = 0;
If (pageno> = totalPage-1)
Endrecord = totalrecord;
Else
Endrecord = (pageno + 1) * pagesize;
Content = '<Table width = "75%" border = "1" cellspacing = "0" bordercolordark = "# ffffff" bordercolorlight = "#339900"> ';
Content + = '<tr> ';
Content + = '<TD width = "45%"> NO. </TD> ';
Content + = '<TD width = "55%"> User Name </TD> ';
Content + = '</tr> ';
For (VAR I = startrecord; I <endrecord; I ++)
{
Content + = '<tr> ';
Content + = '<TD width = "45%">' + dtobj. rows [I] ["ID"] + '</TD>'; // ID, username is column name
Content + = '<TD width = "55%">' + dtobj. Rows [I] ["username"] + '</TD> ';
Content + = '</tr> ';
}
Content + = '<tr align = "center"> ';
Content + = '<TD colspan = "2"> <a href = "#" _ fcksavedurl = "" # "" _ fcksavedurl = "" # "" onclick = "showcontent (/'first /') "> page 1 </a> & nbsp; <a href =" # "onclick =" showcontent (/'previous/') "> previous page </a> & nbsp; <a href = "#" onclick = "showcontent (/'Next/')"> next page </a> & nbsp; <a href = "#" onclick = "showcontent (/'last/')"> last page </a> </TD> ';
Content + = '</tr> ';
Content + = '</table> ';
Invalid Response Doc ument. getelementbyid ("sp_showcontent"). innerhtml = content;
}
Showcontent ("first ");
</SCRIPT>