ASP.NET GridView Tutorial
Lesson 3 of 301 · Object datasource in asp net Part 3 · Database
Object datasource in asp net Part 3
Text version of the video
http://csharp-video-tutorials.blogspot.com/2013/02/object-datasource-in-aspnet-part-3.html
Slides
http://csharp-video-tutorials.blogspot.com/2013/10/part-3-object-datasource-in-aspnet.html
All GridView Text Articles
http://csharp-video-tutorials.blogspot.com/p/free-asp.html
All GridView Slides
http://csharp-video-tutorials.blogspot.com/p/blog-page.html
All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd
All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists
In Part 2 of the asp.net gridview tutorial, we discussed about sqldatasource controls. Please watch Part 2, before proceeding with this video.
Sqldatasource control include sql queries, in the HTML of the aspx page. This may lead to the complexity of the project. That’s why, in real time, sqldatasource control is very rarely used.
Let us understand object datasource, with an example.
Let’s assume our project has the following 3 layers.
1. Presentation Layer – This includes the asp.net web application project, where we have webforms, their code-behind files etc.
2. Business Logic Layer – This is usually a class library project, which includes business objects, like customers, orders, products etc.
3. Data Access Layer – This is usually a class library project, that is responsible for all the database CRUD(Create, Read, Update and Delete) operations.
The above 3 layers interact in the following way.
Presentation Layer – Business Logic Layer – Data Access Layer – Database
Presentation Layer, calls Business Logic Layer which in turn will call, Data Access Layer. Data Access Layer performs all the CRUD operations on the database.
In reality, we may have each layer in it’s own project, but for the purpose of this demo, we will include the data access layer classes in our asp.net web application. We will discuss about building an asp.net web application with n-tier architecture and the difference between layers and tiers in a later video session.
At this point, drag “ObjectDataSource” control from the toolbox and drop it on WebForm1.aspx. Steps to configure “ObjectDataSource”
1. Flip the webform to design mode
2. Click on the little right arrow(Smart Tag). This should display “ObjectDataSource Tasks”
3. Click on “Configure DataSource” link
4. From “Choose your business object” dropdownlist select “Demo.ProductDataAccessLayer” and click “Next”
5. From “Choose a method” dropdownlist, select “GetAllProducts()” and click “Finish”
At this point, we are done, configuring ObjectDataSource control. Now, drag a GridView control from the toolbox and drop it on the webform. Finally associate “ObjectDataSource1” with “GridView1” control using DataSourceID property of “GridView1” control. Run the application and data from “tblProducts” table should now be displayed in the gridview control.