3

up till now i have always created and bind data source on code behind but now i have seen (and used) object date sources on aspx page and bind right there by mentioning listview DataSourceId. if i just want to display data without any change, does it make any difference? in performance or in term of good practice?

Ali Faizan
  • 482
  • 6
  • 13

3 Answers3

0

As discussed in one of SO question
asp.net sqldatasource vs doing it in code behind

Embedding your SQLDataSource or any datasource within the asp.net page is coupling your presentation layer with your data access layer resulting in reduced testability and flexibility. I strongly suggest moving your data connections to their own classes and created a data access layer that your code behind pages could then draw from.

Ideally you'd seperate this even further into an N-Tier solution. Link

Some Useful links
populate gridview via code-behind or markup DataSource?

Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
0

I would say you have alot more control over your control if you bind it in the code behind you can manipulate your results in many creative ways. If you do your databinding in the your markup like with a SelectMethod or OnInit. Every postback or reload will put that data back to what you have in that method. Which can be great for populating a drop down menu that you always want to show the same data. If you want your data to be responsive i would say you have to use DataBind() in your code behind.

I would also think this is a best practice for learning to do more advanced things with your data.

jackncoke
  • 2,000
  • 6
  • 25
  • 66
  • when your writing a program nothing is ever good enough. You always want to do more creative things with your data. – jackncoke Mar 12 '13 at 13:11
0

I would say that it depends on size and scalability of project.

If you want power and control then go for code-behind.

If you want ease-of-use and speed then do things on the page and let the object manage the CRUD

happygilmore
  • 3,008
  • 4
  • 23
  • 37