O'Reilly logo

Learning ASP.NET 2.0 with AJAX by Dan Hurwitz, Jesse Liberty, Brian MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

BRAIN BUILDER

Quiz

  1. What type of control do you need to retrieve data from the database?

  2. What is the name of the process for allowing a control, such as a GridView,to extract data from the retrieved tables and format it properly?

  3. What is a connection string?

  4. What are the four elements of CRUD?

  5. How do you attach a data source to a GridView?

  6. If your table has many rows, what should you do in the GridView to make it easier to read?

  7. What does optimistic concurrency do?

  8. How can you enable users to change the contents of the database from your GridView?

  9. How can you take an action based on the data in a row, as the table is loaded?

  10. How do you filter the amount of data returned from a SELECT query?

Exercises

Exercise4-1. We'll start out easy, letting you create your own GridView. Create a new web site called Exercise 4-1. Add to it a GridView control that shows records from the Product table with a Weight greater than 100. The GridView should list the Product ID, Product Name, Product Number, Color, and List Price. The user should be able to update and delete records, sort by rows, and page through the content. Use the Professional formatting scheme to give it some style. The result should look like Figure 4-27.

Exercise4-2. This one is a little trickier, but it lets you see how users could interact with the data in a GridView. Copy the web site from Exercise 4-1 to a new web site, called Exercise 4-2. Add the ability to select rows in your GridView. Add two labels and two read-only textboxes below the GridView to show the selected item's Product Name and color. The result should look like Figure 4-28.

Exercise4-3. Now it's time to combine what you've learned from previous chapters with the new stuff, and throw a little AJAX into the mix as well. Create a new AJAX-enabled web site called Exercise 4-3. This site should have a radio button that gives readers the opportunity to select whether they want to see data from the Employee table, or the Customer table. The Employee panel should have a GridView showing the EmployeeID, ManagerID, and Title. The Customer panel should have a GridView showing the Customer ID, Account Number, and Customer Type. The table that the reader chooses should appear dynamically in a new panel; the other one should be invisible. The result should look like Figure 4-29.

Your goal for Exercise 4-1.

Figure 4-27. Your goal for Exercise 4-1.

Exercise 4-4. Ready for a bit of a challenge? Sure you are. You're going to see how to retrieve data based on multiple customer selections—like you would in a shopping site. Create a new web site called Exercise 4-4. This site should have three dropdown menus:

  • A Category menu that lists the product categories from the ProductCategory table

  • A Subcategory menu that lists the subcategories of the Category listed in the first drop-down, by using the ProductSubcategory table

    Your goal for Exercise 4-2.

    Figure 4-28. Your goal for Exercise 4-2.

  • A Color menu that lists the available product colors from the Product menu

    In addition, there should be a Submit button that users click. Below all of this is a GridView that displays the Products (from the Product table) that match the chosen subcategory and color. (You don't need to match the category—all that control does is dictate the contents of the Subcategory table.) The GridView should display the ProductID, Name, Product number, and the color, just so you can tell it's working. (Hint: You can use the DISTINCT SQL statement to avoid duplication in your table.) It should look like Figure 4-30.

    Your goal for Exercise 4-3.

    Figure 4-29. Your goal for Exercise 4-3.

    Your goal for Exercise 4-4.

    Figure 4-30. Your goal for Exercise 4-4.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required