AspNetPager分页控件使用方法(一)

AspNetPager分页控件使用方法(一)
一、前台显示界面代码Default.aspx(注意,代码运行环境是VS.2005)
<% @ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default4" %>
<% @ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
< html xmlns="http://www.w3.org/1999/xhtml" >
< head id="Head1" runat="server">
<title>用AspNetPager.dll控件的分页方法操作方法</title>
</ head >
< body >
<form id="form1" runat="server">
<div>
<table border=1>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,"osid")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"year1")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"month1")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"output1")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" NumericButtonCount="6" UrlPaging="true" NumericButtonTextFormatString="[{0}]" CustomInfoHTML=" 第 <font color='red'><b>%CurrentPageIndex%</b></font> 页 共 %PageCount% 页 显示 %StartRecordIndex%-%EndRecordIndex% 条" ShowCustomInfoSection="left"
FirstPageText ="首页" LastPageText="末页" NextPageText="下页" PrevPageText="上页" Font-Names="Arial" BackColor="#F8B500" AlwaysShow="true" ShowInputBox="Always" SubmitButtonText="跳转" SubmitButtonStyle="botton" OnPageChanged="AspNetPager1_PageChanged" >
</webdiyer:AspNetPager>
<% --<webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="15" style="font-size:14px;" HorizontalAlign="Right" NumericButtonCount="6" NumericButtonTextFormatString="[{0}]" CustomInfoHTML="第 <font color='red'><b>%CurrentPageIndex%</b></font> 页 共 %PageCount% 页 显示 %StartRecordIndex%-%EndRecordIndex% 条" InputBoxStyle="width:24px; height:14px;" ShowInputBox="Always" SubmitButtonText=" GO " FirstPageText="[首 页]" PrevPageText="[上 页]" NextPageText="[下 页]" LastPageText="[末 页]" TextBeforeInputBox="转到第" TextAfterInputBox="页 " PagingButtonSpacing="10px" width="100%" ShowCustomInfoSection="Left" UrlPaging="true"></webdiyer:AspNetPager>
-- %>
</div>
</form>
</ body >
</ html >
二、Default.aspx.cs页面的代码
DBAccess db = new DBAccess();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{ BindGrid(); }
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{ BindGrid();
}
public void BindGrid()
{
this.AspNetPager1.RecordCount = Int32.Parse(db.GetAllCount().ToString());
int pageIndex = this.AspNetPager1.CurrentPageIndex - 1;
int pageSize = this.AspNetPager1.PageSize = 20;
Repeater1.DataSource = db.GetCurrentPage(pageIndex, pageSize);
Repeater1.DataBind();
}
三、DBAccess.cs页面的代码
using System.Data.SqlClient;
public class DBAccess
{
private SqlConnection con;
private string DBName = "tongjinet";
//创建连接对象并打开
public void Open()
{
if (con == null)
con = new SqlConnection("server=(local);uid=sa;pwd=sql;database=" + DBName);
if (con.State == ConnectionState.Closed)
con.Open();
}
//创建一个命令对象并返回该对象
public SqlCommand CreateCommand(string sqlStr)
{
Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlStr;
cmd.Connection = con;
return cmd;
}
//生成一个对象并返回该结果集第一行第一列
public object GetScalar(string sqlStr)
{
SqlCommand cmd = CreateCommand(sqlStr);
object obj = cmd.ExecuteScalar();
//CommadnBehavior.CloseConnection是将于DataReader的数据库链接关联起来
//当关闭DataReader对象时候也自动关闭链接
return obj;
}
//执行数据库查询并返回一个数据集 [当前页码,每页记录条数]
public DataSet GetCurrentPage(int pageIndex, int pageSize)
{
//设置导入的起始地址
int firstPage = pageIndex * pageSize;
string sqlStr = "select * from outputsell order by osid desc";
SqlCommand cmd = CreateCommand(sqlStr);
DataSet dataset = new DataSet();
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
dataAdapter.Fill(dataset, firstPage, pageSize, "outputsell");
cmd.Dispose();
Close();
dataAdapter.Dispose();
return dataset;
}
//获得查询数据的总条数
public object GetAllCount()
{
string sqlStr = "select count(*) from outputsell";
object obj = GetScalar(sqlStr);
return obj;
}
//关闭数据库
public void Close()
{
if (con != null)
{
con.Close();
}
}
//释放资源
public void Dispose()
{
if (con != null)
{
con.Dispose();
con = null;
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CutPage.WebForm1" %> <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table width="100%" border="1" cellspacing="0" cellpadding="4" style="border-collapse: collapse"> <tr style="background-color: #CCCCFF"> <th style="width: 10%">激活码</th> <th style="width: 5%">代理商ID</th> <th style="width: 5%">员工ID</th> <th style="width: 5%">激活数量</th> <th style="width: 10%">开始时间</th> <th style="width: 10%">结束时间</th> <th style="width: 20%">公司名称</th> <th style="width: 20%">公司地址</th> <th style="width: 15%">联系电话</th> </tr> </HeaderTemplate> <ItemTemplate> <tr style="background-color: #FAF3DC"> <td><%#DataBinder.Eval(Container.DataItem,"Activation")%></td> <td><%#DataBinder.Eval(Container.DataItem, "DealerId")%></td> <td><%#DataBinder.Eval(Container.DataItem, "UserId")%></td> <td><%#DataBinder.Eval(Container.DataItem, "Quantity")%></td> <td><%#DataBinder.Eval(Container.DataItem, "StartTime")%></td> <td><%#DataBinder.Eval(Container.DataItem, "EndTime")%></td> <td><%#DataBinder.Eval(Container.DataItem, "CompanyName")%></td> <td><%#DataBinder.Eval(Container.DataItem, "CompanyAddress")%></td> <td><%#DataBinder.Eval(Container.DataItem, "CompanyContact")%></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <webdiyer:aspnetpager id="AspNetPager1" runat="server" onpagechanged="AspNetPager1_PageChanged" currentpagebuttonposition="Center" custominfohtml="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条" firstpagetext="首页" lastpagetext="尾页" layouttype="Table" nextpagetext="下一页" pageindexboxtype="DropDownList" pagingbuttonlayouttype="Span" prevpagetext="上一页" showcustominfosection="Left" submitbuttontext="Go" textafterpageindexbox="页" textbeforepageindexbox="转到"> </webdiyer:aspnetpager> </form> </body> </html>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值