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" ...
随机推荐
- Chrome每次打開都要打開123.sogou.com
剛開始還以為中毒了,又是殺毒又是掃描的,最後發覺,原來就是chrome的一個設置被改了. Chrome->設置->啟動時 : 選打开特定网页或一组网页->設置網頁 , 將其中的123 ...
- laravel 删除一条migration后要执行composer命令
Laravel 删除一条migration 字数29 阅读30 评论0 喜欢0 如果迁移已经执行,先回滚php artisan migrate:rollback 然后删除迁移文件,运行composer ...
- js实现的新闻列表垂直滚动实现详解
js实现的新闻列表垂直滚动实现详解:新闻列表垂直滚动效果在大量的网站都有应用,有点自然是不言而喻的,首先由于网页的空间有限,使用滚动代码可以使用最小的空间提供更多的信息量,还有让网页有了动态的效果,更 ...
- Category的使用
1.创建一个objective-c file , 可以选择 category, extension ,protocol, empty 文件.选category 就能建立类别. category机制,它 ...
- centos7安装mysql
centos7安装mysql 1 查找系统是否安装了myql rpm -q mysql mysql-server1.1如果安装了.就删除 sudo yum -y remove mysql mysql- ...
- DIV+CSS滑动门效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 为什么老师不喜欢RelativeLayout
这个要看个人喜好.RelativeLayout对于一些简单布局来说反而复杂了.要计算相对距离这些.用线性布局只要利用好weight可以很直观的实现效果.所以这个因个人喜好而定 对于讲一些简单的功能来说 ...
- textarea文本换行和页面显示换行符
在textarea里写的文本有换行,但是显示到页面后就不会自动换行,通过对数据分析发现textarea里的换行符是\n\r,然而HTML中的换行为<\br>解决办法有两种: 第一种:把文本 ...
- Delphi的Socket编程步骤(repulish)
转贴自:http://topic.csdn.net/t/20010727/16/212155.html ClientSocket 和ServerSocket几个重要的属性: 1.client和se ...
- Droid VNC Server
这个app可以在Android开启VNC Server,让其他的VNC Client远程连接手机,不过前提是要ROOT.哎,可惜了. 当然还有另一款替代品Total Control http://ww ...