在获得了DataTable之后,动态添加一个RowNumber列,以下是代码:

DataColumn col = new DataColumn("RowNumber",Type.GetType("System.Int32"));
   dt.Columns.Add(col);
   for(int i = 0;i<=dt.Rows.Count-1;i++){
    if(0 == i)
     dt.Rows[i][col] = 1;
    else 
     dt.Rows[i][col] = Convert.ToInt32(dt.Rows[i-1][col]) +1;
   }

然后在DataGrid里面绑定RowNumber列。

相关文章:

  • 2022-01-17
  • 2021-10-06
  • 2021-04-28
  • 2022-02-11
  • 2021-07-06
  • 2021-05-12
  • 2022-01-05
猜你喜欢
  • 2021-05-25
  • 2021-08-15
  • 2021-06-21
  • 2021-10-19
相关资源
相似解决方案