To implement data paging operations within a data table:
Web page source data:
<%@ page language= "C #" autoeventwireup= "true" codefile= "Car Fenye.aspx.cs" inherits= "Car__fenye"%>
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<style type= "Text/css" >
#idd {
Font-weight:bold;
Background-color:navy;
Color:black;
Text-align:center;
}
. CLA {
Font-weight:bold;
Background-color:white;
Color:green;
Text-align:center;
}
</style>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:repeater id= "Repeater1" runat= "Server" >
<HeaderTemplate>
<table width= "100%" border= "1" cellpadding= "5" cellspacing= "1" id= "IDD" >
<tr>
<TD width= "5%" > Code </td>
<TD width= "20%" > Name </td>
<TD width= "10%" > Models </td>
<TD width= "25%" > Time </td>
<TD width= "10%" > Fuel consumption </td>
<TD width= "10%" > Power </td>
<TD width= "10%" > Displacement </td>
<TD width= "10%" > Unit price </td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class= "CLA" >
<TD width= "5%" ><%# Eval ("Code")%></td>
<TD width= "20%" ><%# Eval ("Name")%></td>
<TD width= "10%" ><%# Eval ("Branda")%></td>
<TD width= "25%" ><%# Eval ("Timea")%></td>
<TD width= "10%" ><%# Eval ("Oila")%></td>
<TD width= "10%" ><%# Eval ("Powersa")%></td>
<TD width= "10%" ><%# Eval ("Exa")%></td>
<TD width= "10%" ><%# Eval ("Pricea")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
<asp:button id= "Showye" runat= "Server" onclick= "Showye_click" text= "Home"/>
<asp:button id= "Shangye" runat= "Server" onclick= "Shangye_click1" text= "previous page"/>
<asp:button id= "Nextye" runat= "Server" onclick= "Nextye_click1" text= "next page"/>
<asp:button id= "Weiye" runat= "Server" onclick= "Weiye_click" text= "Last"/>
Section <asp:dropdownlist id= "Ddlye" runat= "Server" autopostback= "True" onselectedindexchanged= "Ddlye_ SelectedIndexChanged ">
</asp:DropDownList>
Page Altogether <asp:label id= "Zongye" runat= "Server" forecolor= "Red" ></asp:Label>
Page, now in <asp:label id= "Xianye" runat= "Server" forecolor= "Red" ></asp:Label>
page; <br/>
<br/>
AutoPostBack----automatically post back to the server after the content change is selected </form>
</body>
CS Code:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
public partial class Car__fenye:System.Web.UI.Page
{
Private Const int pagesize=3;//How many data per page
Private Carsdatacontext context = new Carsdatacontext ();
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Showcar ();
Fillye ();
Yshu ();
}
}
private void Showcar ()
//{
var qu = context. Car;
Repeater1.datasource = qu;
Repeater1.databind ();
//}
public void Fillye ()
{
int Tiaoshu=context. Car.count ();//The number of bars for all data in a database table
int yeshu= (int) math.ceiling (1.0*tiaoshu/pagesize);
According to the size of pagesize, to be paged, a page with pagesize data, divided Yeshu pages
for (int i = 0; i < Yeshu; i++)
{
ListItem li = new ListItem ((i + 1). ToString (), i.tostring ());
Ddlye. Items.Add (LI);
}//Add data to DropDownList statically
}
public void Yshu ()
{
int dye = Convert.ToInt32 (Ddlye. SelectedValue);//page 1
int shutiao = dye * pagesize;//The number of pages in front of the total data
var qu = context. Car.skip (Shutiao). Take (pagesize);//paging, Skip takes out all previous bars, shows the number of bars owned by this page
Repeater1.datasource = qu;
Repeater1.databind ();
Zongye. Text = Ddlye. Items.Count.ToString ();//Total number of pages
Xianye. Text = (Ddlye. selectedindex+1). ToString ();//Now on page
//response.write (dye);
//int AAA = Ddlye. SelectedIndex;
//response.write (AAA);
}
protected void Ddlye_selectedindexchanged (object sender, EventArgs e)
{
Yshu ();
}
protected void Showye_click (object sender, EventArgs e)
{
Ddlye. SelectedIndex = 0;
Yshu ();
}
protected void Weiye_click (object sender, EventArgs e)
{
Ddlye. SelectedIndex = Ddlye. items.count-1;
Yshu ();
}
protected void Nextye_click1 (object sender, EventArgs e)
{
if (Ddlye. SelectedIndex < Ddlye. Items.count-1)
{
Ddlye. selectedindex++;
Yshu ();
}
}
protected void Shangye_click1 (object sender, EventArgs e)
{
if (Ddlye. SelectedIndex > 0)
{
Ddlye. selectedindex--;
Yshu ();
}
}
}
Select Top 9 Code from Car;
Select Top 3 * from car where Code not in (select Top 9 Code from car);
Select Ceiling (1.0*count (*)/3) from Car;
C#--web Data Paging