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" ...
随机推荐
- 从千分位格式化谈JS性能优化
所谓的千分位形式,即从个位数起,每三位之间加一个逗号.例如“10,000”.针对这个需求,我起初写了这样一个函数: // 方法一function toThousands(num) {var resul ...
- 转-Activity中使用orientation属性讲解及需注意的问题
http://www.software8.co/wzjs/yidongkaifa/6504.html 今天遇到了一个关于orientation的问题查了点资料记录一下,只有点点滴滴的积累,才能让我们更 ...
- VVDocumenter-Xcode 规范注释生成器 插件之安装调试适应新版本
1.下载地址: 很多时候,为了快速开发,很多的技术文档都是能省则省,这个时候注释就变得异常重要,再配合Doxygen这种注释自动生成文档的,就完美了.但是每次都要手动输入规范化的注释,着实也麻烦,但有 ...
- How To Easily Call WCF Services Properly z
Please note: this article has been superceded by the documentation for the ChannelAdam WCF Library. ...
- delphi 调用百度地图WEBSERVICE转换GPS坐标 转
http://www.cnblogs.com/happyhills/p/3789864.html 百度地图的API说明 使用方法 第一步,申请密钥(ak),作为访问服务的依据: 第二步,按照请求参 ...
- Regex.Replace的基本用法
Regex构造函数Regex(string pattern)Regex(string pattern,RegexOptions options)参数说明pattern:要匹配的正则表达式模式optio ...
- cocos2dx 锁定30帧设置
修改代码: AppDelegate.cpp // set FPS. the default value is 1.0/60 if you don't call this pDirector->s ...
- Android常用知识笔记
1. 安卓图片自适应 android从1.6和更高,Google为了方便开发者对于各种分辨率机型的移植而增加了自动适配的功能 <supports-screens android:largeS ...
- jBox 弹出窗口中焦点设置问题
jBox 是一个不错的组件库,可以用来比较简单地弹出窗口. 我希望在 jBox 弹出窗口之后,自动将焦点设置到子窗口的某个输入框中,可是发现并不容易. 在 jBox 2.3 中,提供了如下的增强. ...
- 一张图看Google MVP设计架构
这段时间看了一下Google官方推出的MVP架构案例,决定把对MVP的理解用类图的形式表述一下.MVP架构的设计思想确实非常值得学习,大家如果还不是很了解MVP,建议抽时间去研究研究,相信对大家的架构 ...