例子:
功能:GridView分页使用图片按钮并添加分页码显示。
默认情况下GridView的分页按钮如果以图片来显示就无法显示文字,这样就无法知道当前所在的页数。
于是,添加分页代码显示就可以显示所在分页的索引数字了。
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient;
public partial class GridView_Page : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//设置分页的图片按钮,这些都可以在控件的属性表上的pagersetting里设置
if (!IsPostBack)
{
GridView1.Caption = "这是一个GridView的小实验";
//Caption属性类似于表名,显示在控件的正上方。
GridView1.PagerSettings.Mode = PagerButtons.NextPreviousFirstLast;
GridView1.PagerSettings.NextPageImageUrl = "img/next.gif";
GridView1.PagerSettings.PreviousPageImageUrl = "img/pre.gif";
GridView1.PagerSettings.FirstPageImageUrl = "img/first.gif";
GridView1.PagerSettings.LastPageImageUrl = "img/last.gif";
GridView1.PageSize = 10; //每页最多显示10条记录;
BindData();
}
}
private void BindData()
{
//将数据部署到GridView中
string Constr = "server=localhost; uid=sa;pwd=123456;database=NorthWind";
string sqlstr = "select * from products";
SqlConnection con = new SqlConnection(Constr);
SqlDataAdapter ad = new SqlDataAdapter(sqlstr, con);
DataSet ds = new DataSet();
ad.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_PageIndexChanged(object sender, EventArgs e)
{
//进行分页之后,重新部署数据
BindData();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//分页完成之前
GridView1.PageIndex = e.NewPageIndex;
}
protected void GridView1_DataBound(object sender, EventArgs e)
{
//添加分页码显示
GridViewRow bottomPagerRow = GridView1.BottomPagerRow;
Label bottomLabel = new Label();
bottomLabel.Text = "目前所在分页:(" + (GridView1.PageIndex + 1) + "/" + GridView1.PageCount + ")";
bottomPagerRow.Cells[0].Controls.Add(bottomLabel);
}
}
WHloud Official Notice(鲸云官方通知)(鲸落 梦之终章)]WHloud RouMu Cloud Hosting若木产品线云主机-香港节点上新预售本次线路均为电信CN2 GIA+移动联通BGP,此机型为正常常规机,建站推荐。本次预售定为国庆后开通,据销售状况决定,照以往经验或有咕咕的可能性,但是大多等待时间不长。均赠送2个快照 2个备份,1个默认ipv4官方网站:https:/...
georgedatacenter怎么样?georgedatacenter这次其实是两个促销,一是促销一款特价洛杉矶E3-1220 V5独服,性价比其实最高;另外还促销三款特价vps,大家可以根据自己的需要入手。georgedatacenter是一家成立于2019年的美国vps商家,主营美国洛杉矶、芝加哥、达拉斯、新泽西、西雅图机房的VPS、邮件服务器和托管独立服务器业务。georgedatacen...
ThomasHost域名注册自2012年,部落最早分享始于2016年,还算成立了有几年了,商家提供基于KVM架构的VPS,数据中心包括美国、法国、英国、加拿大和爱尔兰等6个地区机房,VPS主机套餐最低2GB内存起步,支持Windows或者Linux操作系统,1Gbps端口不限制流量。最近商家提供了一个5折优惠码,优惠后最低套餐月付5美元起。下面列出部分套餐配置信息。CPU:1core内存:2GB硬...