Code in the. aspx page
Copy Code code as follows:
<asp:datalist id= "DataList1" runat= "Server" width= "976px" height= "745px" borderwidth= "2px" cellpadding= "2" cellspacing= "2" repeatcolumns= "7" repeatdirection= "Vertical" bordercolor= "#666666" >
<itemtemplate >
<table >
<tr>
<TD >
<a href= ' <%# "show.aspx?iname=" +eval ("Iname")%> ' > ' width= ' alt= "Click to view the big picture"/></a>
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist><asp:sqldatasource id= "SqlDataSource1" runat= "Server" connectionstring= "<%$" Connectionstrings:s601connectionstring%> "selectcommand=" SELECT [Iname] from [Image] "></asp:sqldatasource >
<table style= "width:976px" cellpadding= "0" cellspacing= "0" >
<tr>
<TD style= "WIDTH:976PX; Text-align:right; font-size:12pt; height:25px; " >
<asp:label id= "LABEL7" runat= "Server" text= "The current page number is:" ></asp:Label>
[
<asp:label id= "Labpage" runat= "Server" text= "1" ></asp:Label>
]
<asp:label id= "Label6" runat= "Server" text= "Total page number is:" ></asp:Label>
[
<asp:label id= "Labbackpage" runat= "Server" ></asp:Label>
]<asp:linkbutton id= "Lnkbtnone" runat= "Server" font-underline= "False" forecolor= "Red"
onclick= "Lnkbtnone_click" > First page </asp:LinkButton>
<asp:linkbutton id= "Lnkbtnup" runat= "Server" font-underline= "False" forecolor= "Red"
onclick= "Lnkbtnup_click" > Prev </asp:LinkButton>
<asp:linkbutton id= "Lnkbtnnext" runat= "Server" font-underline= "False" forecolor= "Red"
onclick= "Lnkbtnnext_click" > next page </asp:LinkButton>
<asp:linkbutton id= "Lnkbtnback" runat= "Server" font-underline= "False" forecolor= "Red"
onclick= "Lnkbtnback_click" > last page </asp:LinkButton> </td>
</tr>
</table>
In the. Aspx.cs page
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
Dlbind ();
}
public void Dlbind ()
{
SqlConnection Sqlcon;
String Strcon = "Data source= (local);D atabase=s601; Uid=sa; pwd=123456 ";
int curpage = Convert.ToInt32 (This.labPage.Text);
PagedDataSource PS = new PagedDataSource ();
Sqlcon = new SqlConnection (Strcon);
Sqlcon. Open ();
String sqlstr = "SELECT [Iname],iid from [Image]";
SqlDataAdapter myadapter = new SqlDataAdapter (Sqlstr, Sqlcon);
DataSet ds = new DataSet ();
Myadapter.fill (ds, "IID");
Ps. DataSource = ds. tables["IID"]. DefaultView;
Ps. AllowPaging = true; Whether you can page pagination
Ps. PageSize = 35; Number of Displays
Ps. CurrentPageIndex = curpage-1; Get the page number of the current page
This.lnkbtnUp.Enabled = true;
This.lnkbtnNext.Enabled = true;
This.lnkbtnBack.Enabled = true;
This.lnkbtnOne.Enabled = true;
if (curpage = 1)
{
this.lnkbtnOne.Enabled = false;//does not display the first page button
this.lnkbtnUp.Enabled = false;//does not display the previous page button
}
if (Curpage = PS. PageCount)
{
this.lnkbtnNext.Enabled = false;//does not display next page
this.lnkbtnBack.Enabled = false;//does not display the last page
}
This.labBackPage.Text = Convert.ToString (PS. PageCount);
This. Datalist1.datasource = PS;
This. Datalist1.datakeyfield = "IID";
This. Datalist1.databind ();
Sqlcon. Close ();
}
protected void Lnkbtnone_click (object sender, EventArgs e)
{
This.labPage.Text = "1";
This.dlbind ();
}
protected void Lnkbtnup_click (object sender, EventArgs e)
{
This.labPage.Text = convert.tostring (Convert.ToInt32 (This.labPage.Text)-1);
This.dlbind ();
}
protected void Lnkbtnnext_click (object sender, EventArgs e)
{
This.labPage.Text = convert.tostring (Convert.ToInt32 (this.labPage.Text) + 1);
This.dlbind ();
}
protected void Lnkbtnback_click (object sender, EventArgs e)
{
This.labPage.Text = This.labBackPage.Text;
This.dlbind ();
}