分页GridView分页系列(精装版)

gridview分页  时间:2021-02-11  阅读:()

GridView分页系列精装版

1 GridView自带分页GridView自带的分页是假分页他每次从数据库把数据全部查询出之后通过分页的算法进行按每页数量进行分页。

分页的属性元素分页功能的实现就是通过对这些属性元素的操作实现的。

//this GvShow PageIndex当前页的索引

//this GvShow PageCount总共的页数

//this GvShow Rows Count当前页签的gridview的行数

//this GvShow PageSize每页的记录数

//this GvShow PageIndex*this GvShow rows count+1 行索引

设置普通的 GridView分页属性Al lowPaging="True" 、 PageSize="2"设置分页事件onpageindexchanging="GvShow_PageIndexChanging"

后台方法绑定protected void GvShow_PageIndexChanging(object sender,GridViewPageEventArgs e)

{this GvShow PageIndex=e NewPageIndex;

BindView();

}

2  自定义样式的GridView自带分页

普通的GridView自带的分页不带样式只是普通的1 ,2,3等如果希望获取到具有其他分页样式就应该设置<PagerSettings Position="TopAndBottom" PageButtonCount="1"/>属性<%--Fi rstPageText="首页"LastPageText="尾页" NextPageText="下一页" PreviousPageText="上一页

"--%>

后台访问此属性的实例this GvShow PagerSettings FirstPageText="首页";this GvShow PagerSettings LastPageText="尾页";this GvShow PagerSettings NextPageText="下一页";this GvShow PagerSettings PreviousPageText="上一页";this GvShow PagerSettings Mode=PagerButtons NextPreviousFirstLast;

通过<PagerStyle HorizontalAl ign="Center" VerticalAl ign="Middle" />属性可以设置GRIDVIEW分页的样式

3 在<Pag e rTem pl ate></Page rTem p late>分页模板中自定义分页的样式虽然微软开辟了这个模板提供给用户类似于自定义分页的功能但这个功能完全还是基于微软的GridView自带的分页进行的 <PagerSettings>属性的 Visable 的属性必须是true Al lowPaging="true"与PageSize="3"属性页都要进行相关的有效设置才可以。这种情况下的分页可以不使用onpageindexchanging="GvShow_PageIndexChanging"微软自带的分页事件开发自己独立的分页事件与方法即可

例

前台代码

<asp:GridView id="GvShow" runat="server"Width="910px"BorderColor="#687BC4"

BorderWidth="1px"PageSize="3"

Cel lPadding="1"HorizontalAl ign="Center"BorderStyle="None"

Al lowPaging="true"

AutoGenerateColum ns="False"onpageindexchanging="GvShow_PageIndexChanging"onrowdatabound="GvShow_RowDataBound"Height="132px"onrowcomm and="GvShow_RowComm and">

<SelectedRowStyle ForeColor="#FFFF99"

BackColor="#FFFF99"></SelectedRowStyle>

<AlternatingRowStyle BackColor="#EEF2F1"></AlternatingRowStyle>

<RowStyle BackColor="White"Height="24"></RowStyle>

<HeaderStyle Wrap="False"HorizontalAl ign="Center"Height="24px"ForeColor="Black"VerticalAl ign="Middle"

BackColor="#BFD5FA"></HeaderStyle>

<%--<PagerSettings Position="TopAndBottom"/>--%>

<%--FirstPageText="首页"LastPageText="尾页" NextPageText="下一页" PreviousPageText="上一页"--%>

<PagerStyle ForeColor="White"HorizontalAlign="Center"

BackColor="ActiveBorder"Font-Underl ine="false" />

<Columns>

<asp:TemplateField HeaderText="省份">

<ItemStyle HorizontalAl ign="Center"

VerticalAlign="Middle"></ItemStyle>

<Item Tem plate>

<asp:Label ID="lblRegionName" runat="server"Text='<%#Eval("rnam e")%>'></asp:Label>

</Item Template>

</asp:Tem plateField>

<asp:TemplateField HeaderText="城市">

<ItemStyle HorizontalAl ign="Center"

VerticalAlign="Middle"></ItemStyle>

<Item Tem plate>

<asp:Label ID="lblCityName" runat="server"Text='<%#Eval("cnam e")%>'></asp:Label>

</Item Template>

</asp:Tem plateField>

<asp:TemplateField HeaderText="用户名">

<ItemStyle HorizontalAl ign="Center"

VerticalAlign="Middle"></ItemStyle>

<Item Tem plate>

<asp:Label ID="lblUserName" runat="server"Text='<%#Eval("usernam e")%>'></asp:Label>

</Item Template>

</asp:Tem plateField>

</Columns>

<PagerTem plate>

<table cellSpacing="0"cel lPadding="0"width="100%"al ign="center"border="0">

<tr>

<td vAl ign="middle"align="center"> 『<asp: l inkbuttonid="cmdbegin" runat="server"CommandName="begin" >首页</asp: l inkbutton>』

『<asp: l inkbutton id="cmdbefore" runat="server"CommandName="before">上一页</asp: l inkbutton>』

『<asp: l inkbutton id="cmdafter" runat="server"CommandName="after" >下一页</asp: l inkbutton>』

『<asp: l inkbutton id="cmdend" runat="server"CommandName="end" >尾页</asp: linkbutton>』

</td>

<td vAl ign="middle"align="center">页次 <asp: labelid="txtNowPage" runat="server"ForeColor="red">0</asp: label>/<asp: label id="txtAl lPage"runat="server"ForeColor="red">0</asp: label>页&nbsp;

共<asp: label id="txtTotal" runat="server"ForeColor="red">0</asp: label>条记录&n bsp;

<asp: label id="txtNowRed" runat="server"ForeColor="red">0</asp: label>条记录/页

</td>

<td vAl ig n="top"al ig n="center"><asp:checkbox

id="cmdCheck" runat="server"Text="显示数字按钮"AutoPostBack="True"oncheckedchanged="cmdCheck_CheckedChanged"></asp:checkbox></td></tr>

</ta b l e>

</PagerTem plate>

</asp:GridView>

后台代码namespace GridViewDemo GridView分页系列

{public partial class GridView自定义分页02:System Web UI Page{protected void Page_Load(object sender,EventArgs e)

{if(! IsPostBack)

{

BindView();

I n itButto ns();

}

}private void BindView()

{

DataTable dt=UserDemoAccess GetUserSouce();

ViewState["RowCounts"]=dt Rows Count ToString();this GvShow DataSource=dt; ;this GvShow DataBind();

}protected void GvShow_PageIndexChanging(object sender,GridViewPageEventArgs e)

{this GvShow PageIndex=e NewPageIndex;

BindView();

I n itButton s();

}protected void GvShow_RowDataBound(object sender,GridViewRowEventArgs e)

{if(e Row RowType==DataControlRowType DataRow)

{e Row Attributes Add("onmouseover",

"this setAttribute('BKC',this style backgroundColor);this style cursor='default',this style backgroundColor='#ffff99'");e Row Attributes Add("onmouseout",

"this style backgroundColor=this getAttribute('BKC');");

}

//if(e Row RowType==DataControlRowType Pager)

//{

// GridViewRow gr=e Row;

// //页次--第几页

// Label txtNowPage=gr FindControl("txtNowPage")as Label ;// //总页数

// Label txtAl lPage=gr FindControl("txtAl lPage")as Label ;// //总记录数

// Label txtTotal=gr FindControl("txtTotal")as Label ;// //条记录/页

// Label txtNowRed=gr FindControl("txtNowRed")as Label ;// txtNowPage Text=(this GvShow PageIndex+1)ToString();// txtAl lPage Text=this GvShow PageCount ToString();// txtTotal Text=ViewState["RowCounts"]ToString();// txtNowRed Text=this GvShow PageSize ToString();

//}

}protected void cmdCheck_CheckedChanged(object sender,EventArgs e)

{

//CheckBox cmdCheck=this GvShow BottomPagerRow FindControl("cmdCheck")asCheckBox;

//if(cmdCheck Checked)

//{

// this GvShow PagerSettings Mode=PagerButtons Numeric;

//}

}protected void GvShow_RowCommand(object sender,GridViewCommandEventArgs e)

{

//控制页签switch(e CommandName)

{case"begin":this GvShow PageIndex=0;

ReadyDedis:VPS全场5折,1G内存套餐月付2美元起,8个机房可选_服务器安装svn

ReadyDedis是一家2018年成立的国外VPS商家,由印度人开设,主要提供VPS和独立服务器租用等,可选数据中心包括美国洛杉矶、西雅图、亚特兰大、纽约、拉斯维加斯、杰克逊维尔、印度和德国等。目前,商家针对全部VPS主机提供新年5折优惠码,优惠后最低套餐1GB内存每月仅需2美元起,所有VPS均为1Gbps端口不限流量方式。下面列出几款主机配置信息。CPU:1core内存:1GB硬盘:25GB ...

ProfitServer$34.56/年,西班牙vps、荷兰vps、德国vps/不限制流量/支持自定义ISO

profitserver怎么样?profitserver是一家成立于2003的主机商家,是ITC控股的一个部门,主要经营的产品域名、SSL证书、虚拟主机、VPS和独立服务器,机房有俄罗斯、新加坡、荷兰、美国、保加利亚,VPS采用的是KVM虚拟架构,硬盘采用纯SSD,而且最大的优势是不限制流量,大公司运营,机器比较稳定,数据中心众多。此次ProfitServer正在对德国VPS(法兰克福)、西班牙v...

捷锐数据399/年、60元/季 ,香港CN2云服务器 4H4G10M

捷锐数据官网商家介绍捷锐数据怎么样?捷锐数据好不好?捷锐数据是成立于2018年一家国人IDC商家,早期其主营虚拟主机CDN,现在主要有香港云服、国内物理机、腾讯轻量云代理、阿里轻量云代理,自营香港为CN2+BGP线路,采用KVM虚拟化而且单IP提供10G流量清洗并且免费配备天机盾可达到屏蔽UDP以及无视CC效果。这次捷锐数据给大家带来的活动是香港云促销,总共放量40台点击进入捷锐数据官网优惠活动内...

gridview分页为你推荐
ptrPTR是什么材料yy频道中心YY怎么进入频道中心淘宝收费淘宝都什么服务是收费的?微信如何建群微信如何建群不兼容vivo手机和软件不兼容怎么办?畅想中国淄博畅想中国消费怎么样xp系统停止服务Windowsxp系统为什么停止服务怎么升级ios6苹果IOS5怎么升级IOS6版本人人逛街人人都喜欢逛街吗mate8价格手机华为mat8售价多少
传奇服务器租用 西安电信测速 asp.net主机 softlayer vpsio NetSpeeder lamp配置 坐公交投2700元 165邮箱 web服务器的架设 老左正传 免费吧 可外链网盘 卡巴斯基试用版 免费测手机号 卡巴斯基破解版 沈阳主机托管 什么是web服务器 金主 上海联通 更多