使用GridView时,哪个是将其绑定到数据源的最佳选择?

时间:2014-03-13 02:23:50

标签: c# asp.net gridview sqldatasource objectdatasource

我对ASP.net相对较新,在学习它时,我遇到了人们用来将数据绑定到GridView的不同方式:

  1. SqlDataSource
  2. 的ObjectDataSource
  3. 从后面的代码中将DataTable绑定到GridView控件。
  4. 首选哪种方式以及在什么情况下?

    谢谢

1 个答案:

答案 0 :(得分:2)

这取决于要求。但是ObjectDataSourceBinding DataTable to GridView control from the code behindSqlDataSource更好。当你使用linq或MVC然后首选ObjectDataSource而对于多层架构,ASP.NET更喜欢Binding DataTable to GridView control from the code behind, 我希望你能得到答案。