1. This is required to add a dll file.
2. Drag the control to the application location and add reference:
Reference:
<% @ Register Assembly = "AspNetPager" Namespace = "Wuqi. Webdiyer" TagPrefix = "webdiyer" %>
Controls:
Copy codeThe Code is as follows:
<Div style = "text-align: center;">
<Webdiyer: AspNetPager ID = "AspNetPagerAskAnswer" runat = "server"
AlwaysShow = "True" FirstPageText = "Homepage" LastPageText = "last page" NextPageText = "next page"
Onpagechanged = "AspNetPagerAskAnswer_PageChanged" PrevPageText = "Previous Page"
PageSize = "15">
</Webdiyer: AspNetPager>
<Br/>
</Div>
(There is a quick and easy way to display the next page on the homepage)
The front-end is basically done here, that is, the background code is compiled:
Copy codeThe Code is as follows:
Private void bind () {SqlConnection connection = new SqlConnection (ConfigurationManager. ConnectionStrings ["tianzi"]. ConnectionString );
SqlCommand cmd = new SqlCommand ("select * from ask", connection );
SqlDataAdapter sda = new SqlDataAdapter (cmd );
DataSet ds = new DataSet ();
AspNetPagerAskAnswer. PageSize = 5; // set the page size
AspNetPagerAskAnswer. RecordCount = AskManager. GetAllAsks (). Rows. Count; // you can specify the total number of data entries.
Sda. Fill (ds, AspNetPagerAskAnswer. PageSize * (AspNetPagerAskAnswer. CurrentPageIndex-1), AspNetPagerAskAnswer. PageSize, "asks"); // fixed
RepeaterAskAnswer. DataSource = ds. Tables ["asks"];
RepeaterAskAnswer. DataBind ();
}
It is okay to write it here, but clicking the page turns to find that the data is the same. Why? We did forget one thing:
Copy codeThe Code is as follows:
Protected void AspNetPagerAskAnswer_PageChanged (object sender, EventArgs e)
{
Bind ();
}
It's almost done here!