如何获取Repeater的当前行号,其实Repeater自身就带有这个获取当前行号的属性,而无需程序员绑定这个行号。到底要怎么实现呢?其实使用Repeater中的 Container.ItemIndex 就可以获取了,见下示例:
Repeater:
<asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> 行号: <%#Container.ItemIndex %> </ItemTemplate> </asp:Repeater>
GirdView:
<asp:GridView ID="GridView2" runat="server"> <Columns> <asp:TemplateField> <ItemTemplate> <%# Container.DataItemIndex %> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
DataList:
<asp:DataList ID="DataList1" runat="server"> <ItemTemplate> <%# Container.ItemIndex %> </ItemTemplate> </asp:DataList>
1. if you are using SQL Server, try
select identity(int,1,1) as 'id', * into #mytemp from YourTable select * from #mytemp
2. you could add a column to the DataTable:
DataTable1.Columns.Add("ID",typeof(int)); int i=0; foreach (DataRow dr in DataTable1.Rows) { dr["ID"] = ++i; }