GridView控件中加自动排列序号
GridView控件中加自动排列序号
为 Gridview 增加一个新的空白列,如下:
<asp:BoundField HeaderText="序号">
<ItemStyle HorizontalAlign="Center" Width="26px" />
</asp:BoundField>
在 GridView RowDataBound 事件中编写代码,如下:
protected void RowDataBond1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex > -1)
{
e.Row.Cells[0].Text = Convert.ToString(e.Row.RowIndex + 1);
}
}
这样就会在运行时自动创一个顺序编号的字段。
也可以在前台直接写
此处是用GridView自带分页
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<%# this.GridView1.PageIndex * this.GridView1.PageSize + GridView1.Rows.Count + 1%>
</ItemTemplate>
</asp:TemplateField>
下面是用AspNetPager分页控件的情况:
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<%# (this.Pager1.CurrentPageIndex - 1) * this.Pager1.PageSize + Container.DataItemIndex + 1%>
</ItemTemplate>
</asp:TemplateField>
当没有分页时的情况:
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<%# Container.DataItemIndex + 1%>
</ItemTemplate>
</asp:TemplateField>
GridView控件中加自动排列序号的更多相关文章
- GridView控件中插入自定义删除按钮并弹出确认框
GridView控件中插入自定义删除按钮,要实现这个功能其实有多种方法,这里先记下我使用的方法,以后再添加其他方法. 一.实现步骤 1.在GridView中添加模板列(TemplateField). ...
- GridView控件中Checkbox实现单选
在GridView控件中,第0列有放一个CheckBox控件,现想实现对CheckBox进行单选. 先看看效果: 在ASPX页面,可以这样做: 有一点注意的是需要使用OnRowCreated事件. 在 ...
- GridView内按钮Click获取记录主键值 在GridView控件中,每行记录内会放置一个铵钮,当用
在GridView控件中,每行记录内会放置一个铵钮,当用户点击这个铵钮时,获取当笔记录的主键值.可看演示(是一个gif动画,重新播放尝试刷新网页): 实现这个功能,你需要为GridView控件设置Da ...
- GridView 控件中如何绑定 CheckBoxList
需求:设计这样一个页面,在页面上可以选择和展示各省份对应的文明城市? 思路:一次性查询出所需的记录(查询数据库的操作不宜写到 C# 代码的循环语句中),并保存到全局变量中,之后根据条件过滤出需要的.可 ...
- GridView控件中的一些常见问题
1. 无法获取模板列中的值,使用FindControl()方法无效: 给模板列中添加隐藏域,并给隐藏域绑定要获取的值,代码如下: <asp:HiddenField ID="hfIsFr ...
- asp.net 在repeater控件中加按钮
在repeater中加入方法有两种方法: 第一种:是对repeater控件的行添加OnItemCommand事件,添加方法也是有两种 1.在设计页面中,选中repeater控件右击==>属性== ...
- 在Gridview控件中根据Field Name来取得对应列索引
下面方法,只能在Gridview的BoundField进行操作,而在TemplateField模版中去找的话,就无能为力了,因TemplateField模版没有DataField属性. public ...
- asp.net GridView控件中诗选全选和全不选功能
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- 【高德地图API】Pivot控件中加载地图并禁止Pivot手势
如题,解决方案,参考[Windows phone应用开发[20]-禁止Pivot手势]http://www.cnblogs.com/chenkai/p/3408658.html. xaml代码清单 ...
随机推荐
- 【转】Struts1.x系列教程(4):标签库概述与安装
转载地址:http://www.blogjava.net/nokiaguy/archive/2009/01/archive/2009/01/archive/2009/01/archive/2009/0 ...
- 覆盖的面积(HDU 1255 线段树)
覆盖的面积 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem D ...
- 2015弱校联盟(1) -A. Easy Math
A. Easy Math Time Limit: 2000ms Memory Limit: 65536KB Given n integers a1,a2,-,an, check if the sum ...
- HDU1532 Drainage Ditches 网络流EK算法
Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...
- 用unity3d+cardboard开发一个全景图片查看器
一.建立全景播放场景: 建立一个unity项目,并建立videoplay场景,在场景中拖入一个球体,将全景照片拉到球体上,自动形成material和texture. 二.创建一个新的表面着色器,并修改 ...
- Unity-Animator深入系列---API详解
回到 Animator深入系列总目录 测试Unity版本为5.2.1 人形动画的接口都有标注 本列表不包含所有标注为过时的方法 1.Vector3 angularVelocity { get; } [ ...
- Trying to hack Redis via HTTP requests
Trying to hack Redis via HTTP requests Context Imagine than you can access a Redis server via HTTP r ...
- C/C++与Matlab混合编程
Matlab 拥有丰富的功能,编程简单.不过,有些情况下,Matlab程序的执行速度比较慢.C/C++编译执行的程序速度比较快,编程难度上比Matlab要高一些.因此存在一种方案,就是使用Matlab ...
- python yield的初识
---------2016-5-18 10:49:45-- source:
- html之meta详解
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --> <html lang="zh-cmn-Hans"&g ...