ASP.NET(C#)--Repeater中生成“序号”列
需求介绍:在Repeater(Table)中加入“序号”列,从1开始自增,步长为1。
思路:因为“序号”跟Repeater的行号有关,所以要在Repeater的ItemDataBound事件中输出“序号”的值。为方便给“序号”赋值,我们使用Label控件。
注意:Repeater的ItemIndex是从0开始的,而“序号”列是从1开始的,所以ItemIndex要加1。
前台代码如下图所示:
前台代码
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate>
<table border="" style="border-color: #000000; border-collapse: collapse; width: 100%;
text-align: center; word-spacing: normal; font-size: 13px;" cellpadding="">
<tr height="" style="background-color: #66CCFF; font-weight: bold;">
<td>
序号
</td>
<td>
合同号
</td>
<td>
设备名称
</td>
<td>
设备型号
</td>
<td>
数量
</td>
<td>
入库时间
</td>
<td>
操作
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style='background-color: <%#(Container.ItemIndex%2==0)?"#eeeeee":"#ffffff"%>'
onmouseover="this.style.background='#ddeeff'" onmouseout="this.style.background='<%#(Container.ItemIndex%2==0)?"#eeeeee":"#ffffff"%>'">
<td>
<asp:Label ID="no" runat="server" Text=""></asp:Label>
</td>
<td>
<%# DataBinder.Eval(Container, "DataItem.contract_no")%>
</td>
<td>
<%# DataBinder.Eval(Container, "DataItem.assets_name")%>
</td>
<td>
<%# DataBinder.Eval(Container, "DataItem.assets_model")%>
</td>
<td>
<%# DataBinder.Eval(Container, "DataItem.assets_amount")%>
</td>
<td>
<%# DataBinder.Eval(Container, "DataItem.in_time")%>
</td>
<td>
<asp:HyperLink ID="HyperLink1" runat="server" Target="_blank" NavigateUrl='<%#"storage_details.aspx?storage_id="+DataBinder.Eval(Container, "DataItem.ID") %>' Text="明细"></asp:HyperLink>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
后台代码如下图所示:
后台代码
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lb_no = (Label)e.Item.FindControl("no");
lb_no.Text = ( + e.Item.ItemIndex).ToString();
}
}
ASP.NET(C#)--Repeater中生成“序号”列的更多相关文章
- OAF TABLE中添加序号列
在实际的OAF页面TABLE的使用中,会有很多时候需要在前台页面中显示序号,虽然在sql中可以使用rownum来获得序号,但是rounum的优先级比order by 高,所以在语句中order by ...
- (转)Repeater中增加序号自增列
<%# Convert.ToString(Container.ItemIndex+)%> 当Repeater空为时,提示没有数据... <FooterTemplate> < ...
- GridView,Repeater增加自动序号列
有三种实现的方式, 第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. <Columns> <asp:TemplateField Hea ...
- aspxgridView,Repeater增加自动序号列
第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. <asp:TemplateField HeaderText="序号" Ins ...
- easyui datagrid生成序号列formatter
var opts1; $('#datagrid_1').datagrid({ columns: [ [{ field: 'myNo', title: '序号', align: 'center', wi ...
- asp,对待绑定数据加序号列(DataSet)
string sql_sel = "select InS.ID as isID, InS.InventorySize , InS.MinValue,InS.MaxValue from Inv ...
- MySQL自动生成序号列
select (@i:=@i+1) i,a.CITYID from basis_cityinfo a ,(select @i:=0) t2 order by a.id desc limit 220;
- datatable 加序号列
最近使用datatable时,发现没有像jqgrid那样生成序号列,在国外网站搜罗了一下还是很简单的,就要在aoColumns中添加一空列占位就行,然后再用fnRowCallback添加序号 示例如下 ...
- element-UI el-table添加序号列时序号永远都是从1开始?
Part.1 示例 当我们想在 el-table 中添加序号列时,如下: <el-table-column label="序号" type="index" ...
随机推荐
- php 信号量
一些理论基础: 信号量:又称为信号灯.旗语 用来解决进程(线程同步的问题),类似于一把锁,访问前获取锁(获取不到则等待),访问后释放锁. 临界资源:每次仅允许一个进程访问的资源. 临界区:每个进程中访 ...
- [实变函数]3.2 可测集 (measurable set)
1 $\bbR^n$ 中集合 $E$ 称为可测的 (measurable), 如果 $$\bee\label{3.2:Caratheodory} m^*T=m^*(T\cap E)+m^*(T\cap ...
- Mobirise
网站建设器Mobirise v1.9.2 免费版 - 绿色软件联盟 2015年9月5日 - 网站建设器Mobirise是一个用户友好的程序,使您可以构建桌面和移动网站,准备在Javas cript中. ...
- Windows XP下安装和配置Apache2.2.22服务器+PHP5+Mysql5
原文:http://www.chinaz.com/web/2012/0516/252021.shtml 随着PHP网站的流行,国内越来越多的站长使用php开发网站或者使用相关的php开源网站(例如:D ...
- iOS 热点、通话时候TabView的Frame调整
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame{ ...
- java web session监听销毁跳转
1.了解如何使用HttpSessionListener监听session的销毁. 2.了解如何使用HttpSessionBindingListener监听session的销毁. 一. 使用HttpSe ...
- [ActionScript] AS3代码实现渐变遮罩效果
import flash.display.Shape; import flash.display.GradientType; import flash.geom.Matrix; import flas ...
- Adobe AIR socket complicating 导致 socket RST
基于socket实现HTTP协议 并发请求AB,A为HTTP请求,B为socket请求. A的请求服务器返回数据很短,包体长度只有35,且客户端收到包头后就断开连接,同时A连接的服务器也断开了连接, ...
- phpmyadmin #2003 无法登录 MySQL服务器的解决方法
本文章向大家介绍phpmyadmin #2003 无法登录 MySQL服务器的解决方法,需要的码农可以参考一下. 通过phpmyadmin连接mysql数据库时提示:"2003 无法登录 M ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(12)-Run-As认证服务
有这样一些场合,系统用户必须以其他角色身份去操作某些资源.例如,用户A要访问资源B,而用户A拥有的角色为AUTH_USER,资源B访问的角色必须为AUTH_RUN_AS_DATE,那么此时就必须使用户 ...