需求介绍:在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中生成“序号”列的更多相关文章

  1. OAF TABLE中添加序号列

    在实际的OAF页面TABLE的使用中,会有很多时候需要在前台页面中显示序号,虽然在sql中可以使用rownum来获得序号,但是rounum的优先级比order by 高,所以在语句中order by ...

  2. (转)Repeater中增加序号自增列

    <%# Convert.ToString(Container.ItemIndex+)%> 当Repeater空为时,提示没有数据... <FooterTemplate> < ...

  3. GridView,Repeater增加自动序号列

    有三种实现的方式, 第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. <Columns> <asp:TemplateField Hea ...

  4. aspxgridView,Repeater增加自动序号列

    第一种方式,直接在Aspx页面GridView模板列中.这种的缺点是到第二页分页时又重新开始了. <asp:TemplateField HeaderText="序号" Ins ...

  5. easyui datagrid生成序号列formatter

    var opts1; $('#datagrid_1').datagrid({ columns: [ [{ field: 'myNo', title: '序号', align: 'center', wi ...

  6. asp,对待绑定数据加序号列(DataSet)

    string sql_sel = "select InS.ID as isID, InS.InventorySize , InS.MinValue,InS.MaxValue from Inv ...

  7. MySQL自动生成序号列

    select (@i:=@i+1) i,a.CITYID from basis_cityinfo a ,(select @i:=0) t2 order by a.id desc limit 220;

  8. datatable 加序号列

    最近使用datatable时,发现没有像jqgrid那样生成序号列,在国外网站搜罗了一下还是很简单的,就要在aoColumns中添加一空列占位就行,然后再用fnRowCallback添加序号 示例如下 ...

  9. element-UI el-table添加序号列时序号永远都是从1开始?

    Part.1 示例 当我们想在 el-table 中添加序号列时,如下: <el-table-column label="序号" type="index" ...

随机推荐

  1. centos7编译安装nginx1.8

    安装pcre wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz tar -zxvf pcre-8. ...

  2. ubuntu 格式化U盘,并制作系统镜像

    1. 先要卸载U盘,使用如下命令: #umount /dev/sdb1 注意:/dev/后面的设备要根据你的实际情况而定,否则后面格式化,丢失数据!! 格式化U盘,并建立vfat文件系统 #mkfs. ...

  3. 一步步教你如何把电脑设置U盘启动(图解教程)

    一.我们先来说说如何进入 BIOS设置程序: 在开机时按下特定的热键可以进入BIOS设置程序,不同类型的机器进入BIOS设置程序的按键不同,有的在屏幕上给出提示,有的不给出提示,几种常见的BIOS设置 ...

  4. [ActionScript 3.0] AS3 双A字模型

    package { import caurina.transitions.Tweener; import flash.display.Sprite; import flash.events.Mouse ...

  5. 为何你的php代码没有写结束标签

    PHP闭合标签"?>"在PHP中对PHP的分析器是可选的.但是,如果使用闭合标签,任何由开发者,用户, 或者FTP应用程序插入闭合标签后面的空格都有可能会引起多余的输出.ph ...

  6. golang.org/x/mobile/exp/gl/glutil/glimage.go 源码分析

    看这篇之前,建议先看之前几篇,这几篇是基础. Go Mobile 例子 basic 源码分析 http://www.cnblogs.com/ghj1976/p/5183199.html OpenGL ...

  7. C#实现程序自重启

    方法1: System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); / ...

  8. DataRow对象的行状态(RowState)和行版本(DataRowVersion)属性

    DataRow对象有两个比较重要的属性,分别是行状态(RowState)和行版本(DataRowVersion),通过这两个属性能够有效的管理表中的行.下面简要的介绍一下行状态和行版本的特点和关系. ...

  9. HDU 5521 [图论][最短路][建图灵感]

    /* 思前想后 还是决定坚持写博客吧... 题意: n个点,m个集合.每个集合里边的点是联通的且任意两点之间有一条dis[i]的边(每个集合一个dis[i]) 求同时从第1个点和第n个点出发的两个人相 ...

  10. cocos2d-x 菜单

    菜单在游戏中是非常常见的控件之一.下面来分析下在cocos2dx中有那些菜单. 一共有六种菜单. CCMenu在创建时需要使用CCMenuItem来创建. CCMenu继承自CCLayer,是一个菜单 ...