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>
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();
}
如要制作无刷新分页
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>
</