NET 分页控件的使用

1.添加引用
2.aspx
文件加入
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
3.aspx
文件加入
<asp:DataGrid ID="VideoAdmin" runat="server">
</asp:DataGrid>
<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" OnPageChanging="AspNetPager1_PageChanging"></webdiyer:AspNetPager>
具体参数根据需求自定
4.cs
文件引入命名空间
using Wuqi.Webdiyer;
6.
初始化数据绑定
if (!IsPostBack)
{
string SqlStr = "select count(*) from *";
AspNetPager1.RecordCount = SqlHelper1.selcount(SqlStr); //
查询记录总数赋值给AspNetPager1
//SqlHelper1.selcount
是自定义操作数据库方法
DataGridDataBind(); //
数据绑定DataGrid
}
7.
数据绑定方法--自定义分页
private void DataGridDataBind()
{
string SqlStr = "select * from *";
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connectionStrings"]);
//
创建数据适配器对象
SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
//
创建DataSet对象
DataSet ds = new DataSet();
try
{
//
从指定的索引开始取PageSize条记录
da.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "CurDataTable");
//
填充数据集
da.Fill(ds, "AllDataTable");
//
设置DataGrid控件实际要显示的项数
VideoAdmin.VirtualItemCount = ds.Tables["AllDataTable"].Rows.Count;
//
进行数据绑定
VideoAdmin.DataSource = ds.Tables["CurDataTable"];
VideoAdmin.DataBind();
}
catch(Exception error)
{
Response.Write(error.ToString());
}
}
8.
分页控件事件
protected void AspNetPager1_PageChanging(object src, PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
DataGridDataBind();
}
AspNetPager.dll下载

如要制作无刷新分页
magicajax.dll下载
1.
添加引用
2.
配置webconfig
<system.web>
<httpModules>
<add name="MagicAjaxModule" type="MagicAjax.MagicAjaxModule, MagicAjax"/>
</httpModules>
</system.web>
3.aspx
页面加入<%@ Register Assembly="MagicAjax" Namespace="MagicAjax.UI.Controls" TagPrefix="ajax" %>
4.aspx
页面加入
<ajax:AjaxPanel id="AjaxPanel1" runat="server">
<asp:DataGrid ID="VideoAdmin" runat="server">
</asp:DataGrid>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server">
</webdiyer:AspNetPager>
</ajax:AjaxPanel>
posted @ 2008-05-02 21:23  chunchill  阅读(227)  评论(0编辑  收藏  举报