Asp tutorial. net aspnetpager paging code
@ Page language = "c #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "test_default" stylesheettheme = "default" %>
<%... @ Register assembly = "aspnetpager" namespace = "wuqi. webdiyer" tagprefix = "webdiyer" %>
<Html xmlns = "http://www.111cn.net/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: datalist id = "datalist1" runat = "server">
<Itemtemplate>
Productname:
<Asp: label id = "productnamelabel" runat = "server" text = '<% # eval ("productname") %>'>
</Asp: label> <br/>
<Br/>
</Itemtemplate>
</Asp: datalist>
<Webdiyer: aspnetpager id = "pager1" runat = "server" onpagechanged = "changepage"> </webdiyer: aspnetpager>
</Div>
</Form>
</Body>
</Html>
<%
Using system;
Using system. data;
Using system. configuration;
Using system. collections;
Using system. web;
Using system. web. security;
Using system. web. ui;
Using system. web. ui. webcontrols;
Using system. web. ui. webcontrols. webparts;
Using system.web.ui.html controls;
Using cpp114.tools. oledb;
Using system. data. oledb;
Using wuqi. webdiyer;
Public partial class test_default: system. web. ui. page
...{
Protected oledbconnection conn = new oledbconnection ();
Protected oledbcommand cmd = new oledbcommand ();
Protected void page_load (object sender, eventargs e)
...{
If (! Ispostback )...{
Initdb ();
Conn. open ();
Cmd. commandtext = "select count (*) from t_product ";
Pager1.recordcount = (int00000000.exe cutescalar ();
Conn. close ();
Binddata ();
}
}
// Initialize the connection object
Protected void initdb ()...{
Conn. connectionstring = oledbtool. myconnstr + server. mappath (oledbtool. mydbname );
Cmd. connection = conn;
}
// Data binding
Protected void binddata ()...{
Initdb ();
Oledbdataadapter sda = new oledbdataadapter ("select * from t_product", conn );
Dataset ds = new dataset ();
// Sda. fill (ds, 10, 10, "temptbl ");
Sda. fill (ds, pager1.pagesize * (pager1.currentpageindex-1), pager1.pagesize, "temptbl ");
Datalist1.datasource = ds. tables ["temptbl"];
Datalist1.databind ();
}
// Page flip event
Protected void changepage (object src, pagechangedeventargs e)
...{
Pager1.currentpageindex = e. newpageindex;
Binddata ();
}
}