How can I export a GridView.DataSource to a datatable or dataset?

后端 未结 7 1147
心在旅途
心在旅途 2020-11-28 08:45

How can I export GridView.DataSource to datatable or dataset?

7条回答
  •  抹茶落季
    2020-11-28 08:59

    Personally I would go with:

    DataTable tbl = Gridview1.DataSource as DataTable;
    

    This would allow you to test for null as this results in either DataTable object or null. Casting it as a DataTable using (DataTable)Gridview1.DataSource would cause a crashing error in case the DataSource is actually a DataSet or even some kind of collection.

    Supporting Documentation: MSDN Documentation on "as"

提交回复
热议问题