The Product Details Page
Like the product categories page in Listing 1
, the ASP.NET page that displays product details also uses an ObjectDataSource control. The key difference is that the ObjectDataSource control retrieves a ProductID
value (passed via a URL query string) and passes that as an argument to the GetProductDetailsByProductID()
method (see Listing 4
When you click on a specific product hyperlink in the product categories page, you'll see a page similar to Figure 2
The Department Page
|Figure 2. Product Details Page: This page displays the details of a specific product.|
In addition to displaying the products and categories information, the AdventureWorks web site also exposes a feature to add a new department to the Department table. Listing 5
shows the code for the web page supporting that feature:
Note that the deptSource
control has its InsertMethod
attribute set to InsertDepartment()
, which accepts an argument of type DepartmentInfo. To pass an object as an argument to the method, you set the DataObjectTypeName
attribute to the name of the object. The TypeName
attribute is set to "Departments," which is the class that handles the communication required to perform CRUD operations against the Department
table (see Listing 6
The Departments class has two methods: GetDepartments() and InsertDepartment(). The InsertDepartment() method accepts an object of type DepartmentInfo. As the name suggests, this is a placeholder class that just contains properties for holding department related attributes (see Listing 7).
If you navigate to the department Web page from the browser you'll see a page similar to Figure 3.
|Figure 3. The Departments Page: This page displays all the departments with paging enabled in a DetailsView control. By clicking on the New hyperlink, you can add a new department to the departments table.|
|Figure 4. Add Department Page: This page lets you enter new department details and then save the new department to the database by clicking on the Insert hyperlink.||
To add a department, click on the "New" link in Figure 3
. You will be redirected to a page wherein you can enter the new department details (see Figure 4
Now that I've described the application's structure, the rest of this article concentrates on migrating the application to use LINQ.