DataList绑定DataSet后让每一行产生一个行号

来源:互联网 发布:linux recv sleep 编辑:程序博客网 时间:2024/05/06 14:31

DataList绑定DataSet后如何让每一行产生一个行号?
或者在数据库读出时产生行号也行。
______________________________________________________________________________________________
答1:
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;
}

3. or you can use in your template

<%# Container.ItemIndex+1 %>
______________________________________________________________________________________________