AspNetPager的使用实例说明
2、在页面上拖放控件
3、
<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>
4、控件的基本属性设置
<webdiyer:AspNetPager ID="AspNetPager1" runat="server"
FirstPageText='首页'
LastPageText='尾页' PagingButtonSpacing="10px" ShowPageIndexBox="Always" CustomInfoHTML="共%RecordCount%条,第%CurrentPageIndex%页 /共%PageCount% 页"
NextPageText="下一页" PrevPageText ="上一页"
ShowCustomInfoSection="Left"
SubmitButtonText ="Go" TextAfterPageIndexBox ="页"
TextBeforePageIndexBox ="转到 " UrlPaging="True"
CustomInfoSectionWidth="20%" CustomInfoTextAlign="Center"
onpagechanged="AspNetPager1_PageChanged">
</webdiyer:AspNetPager>
5、后台代码
protected void Page_Load(object sender, EventArgs e)
{
string sqlStr = "select * from download where 1=1 ";
if (key.Text != "")
{
sqlStr += "and title like '%" + key.Text + "%' order by id desc";
}
else
{
sqlStr += "order by id desc";
}
string s = ConfigurationManager.ConnectionStrings["siteconn"].ConnectionString; //定义连接字符串
SqlConnection conn = new SqlConnection(s); //新建数据库连接对象,其中s是上面的连接字符串
conn.Open(); //打开与数据库的连接
SqlCommand cmd = new SqlCommand(sqlStr, conn);
AspNetPager1.AlwaysShow = true;
AspNetPager1.PageSize = 15;
AspNetPager1.RecordCount = (int)cmd.ExecuteScalar();
conn.Close();
bind();
}
private void bind()
{
string sqlStr = "select * from download where 1=1 ";
if (key.Text != "")
{
sqlStr += "and title like '%" + key.Text + "%' order by id desc";
}
else
{
sqlStr += "order by id desc";
}
string s = ConfigurationManager.ConnectionStrings["siteconn"].ConnectionString; //定义连接字符串
SqlConnection conn = new SqlConnection(s); //新建数据库连接对象,其中s是上面的连接字符串
conn.Open(); //打开与数据库的连接
DataSet myds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(sqlStr, conn);
adapter.Fill(myds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "myds");
GridView1.DataSource = myds.Tables["myds"];
GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
bind();
}
6、添加序号
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<%# (this.AspNetPager1.CurrentPageIndex - 1) * this.AspNetPager1.PageSize + Container.DataItemIndex + 1%>
</ItemTemplate>
</asp:TemplateField>
上一篇: .net控件页面处用js赋值后台接收不到数据的解决方案
下一篇: C++与设计模式(14)职责链模式
推荐阅读
-
jQuery内置的AJAX功能和JSON的使用实例教程
-
基于ECMAScript6即ECMAScript2015的javascriptclass类封装的简单使用实例讲解
-
Linux系统中cat命令使用的实例教程
-
PHP下编码转换函数mb_convert_encoding与iconv的使用说明
-
AngularJS的依赖注入实例分析(使用module和injector)
-
vue+axios实现文件下载及vue中使用axios的实例
-
UG10.0使用变化扫略功能绘图的实例教程
-
使用NumPy和pandas对CSV文件进行写操作的实例
-
C# 使用GDI绘制雷达图的实例
-
python使用response.read()接收json数据的实例