Default. aspx. CS:
Public partial class _ default: system. Web. UI. Page
{
String connectstring = "";
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" %>
<HTML>
<Head runat = "server">
<Title> </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 ();
Dtobj = _ default. getdatatable (). value;
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 = ""#""
_ 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>