最近做一个相册程序频繁的需要分页,所以就想写一个用户控件出来。
代码如下:
AutoPage.ascx页面
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="AutoPage.ascx.cs" Inherits="album.AutoPage" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="middle" height="30">共<asp:label id="lb_ItemCount" ForeColor="Red" runat="server"></asp:label>条记录 </td>
<td valign="middle" height="30"><asp:hyperlink id="hpl_First" runat="server">首页</asp:hyperlink> </td>
<td valign="middle" height="30"><asp:hyperlink id="hpl_Prev" runat="server">上页</asp:hyperlink> </td>
<td valign="middle" height="30">当前<asp:label id="lb_CurrentPage" runat="server"></asp:label>页/共<asp:label id="lb_PageCount" runat="server"></asp:label>页 </td>
<td valign="middle" height="30"><asp:hyperlink id="hpl_Next" runat="server">下页</asp:hyperlink> </td>
<td valign="middle" height="30"><asp:hyperlink id="hpl_Last" runat="server">末页</asp:hyperlink> </td>
<td valign="middle" height="30"><asp:textbox id="txb_Page" runat="server" Width="32px" BorderStyle="Solid" BorderWidth="1px"
BorderColor="Silver"></asp:textbox></td>
<td valign="middle" height="30"><asp:ImageButton id="btn_go" runat="server" ImageUrl="album_images/go.gif"></asp:ImageButton></td>
<td valign="middle" height="30"><asp:label id="lb_url" runat="server" Visible="False"></asp:label><asp:Label id="lb_Params" runat="server" Visible="False"></asp:Label></td>
</tr>
</table>
AutoPage.ascx.cs页面
namespace album
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// UC 的摘要说明。
/// </summary>
public class AutoPage : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.HyperLink hpl_First;
protected System.Web.UI.WebControls.HyperLink hpl_Prev;
protected System.Web.UI.WebControls.HyperLink hpl_Next;
protected System.Web.UI.WebControls.Label lb_CurrentPage;
protected System.Web.UI.WebControls.Label lb_PageCount;
protected System.Web.UI.WebControls.HyperLink hpl_Last;
public int pagesize;
public string PageP;
protected System.Web.UI.WebControls.TextBox txb_Page;
protected System.Web.UI.WebControls.Label lb_url;
protected System.Web.UI.WebControls.Label lb_ItemCount;
public string url;
protected System.Web.UI.WebControls.Label lb_Params;
protected System.Web.UI.WebControls.ImageButton btn_go;
public string Params;
private void Page_Load(object sender, System.EventArgs e)
{
}
public PagedDataSource databind(DataTable dt)
{
lb_url.Text = url;