在datatable中添加一序号列

http://topic.csdn.net/t/20050324/09/3876414.html
int colLength = dt.Rows.Count;
            
int rowLength = dt.Columns.Count;
            DataRow
[] newRows = new DataRow[rowLength];
            DataTable subDT 
= new DataTable();
           
            
for (int i = 0; i < colLength; i++)
            {
                subDT.Columns.
Add();
                
for (int j = 0; j < rowLength; j++)
                {
                    
                    
if (newRows[j] == null) newRows[j] = subDT.NewRow();
                    newRows
[j][i] = dt.Rows[i][j];

                }
            }
            foreach (DataRow row 
in newRows)
            {
                subDT.Rows.
Add(row);
            }
            DataRow dr 
= subDT.NewRow();   
       dr
[0]="aaa";   
       dr
[1]="bbb";
       subDT.Rows.
Add(dr);


            GridView3.DataSource 
= subDT;
            GridView3.DataBind();
posted @ 2007-06-11 18:04  wdx2008  阅读(815)  评论(0编辑  收藏  举报