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" ...
随机推荐
- CSS背景属性Background详解
[转] 本文详解了CSS的背景属性Background,包括CSS3中新增的背景属性.如果你是个CSS初学者,还可以查看之前介绍的CSS浮动属性和CSS透明属性详解. CSS2 中有5个主要的背景(b ...
- JavaScript笔记之数组 keyword(存储和释放&堆栈 & 按值 引用)
1.数组创建及初始化 var obj=new Array(); var arr=[]; 可以延伸为长度一定的,字面量定义数组 2.堆栈 按值传递 引用类型 数组是引用类型,不是值传递, 栈:系桶自动分 ...
- $.extend()和$.fn.extend()用法和区别
$.extend()和$.fn.extend()用法和区别: 在自己制作插件的时候会经常用到$.extend()和$.fn.extend()两个函数,无论从外观还是作用都非常的类似,但是实际上它们的区 ...
- iOS获取电量方法
ios简单的方法: [UIDevice currentDevice].batteryMonitoringEnabled = YES; double deviceLevel = [UIDevice cu ...
- 在Virtual Box虚拟机中安装MS DOS!
原文地址:https://mylinuxramblings.wordpress.com/2010/12/05/linux-mint-debian-edition-lmde-first-impressi ...
- vim操作笔记
1.切换到下一个文件 假设要切换的文件名为 test.py :ex test.py 2.文档内复制命令 yy "复制光标所在行.或大写一个Y. 2yy "复制两行. y^ &quo ...
- Java基础-绘图技术
- 离线安装PM2
因为要部署应用的机器没有公网连接,所以直接npm install pm2是不可能了, 简单记录一下怎么离线安装pm2 首先,找一台可以在线安装pm2的机器 执行 npm install pm2 -g ...
- .NET 验证码/验证图片
/// <summary> /// 验证码类 /// </summary> public class Rand { #region 生成随机数字 /// <summary ...
- java常用面板
public class JPanelTest extends JFrame{ public JPanelTest(){ Container c=getContentPane(); ...