Creating the Employee List Page


You will be using all of the functionality of your existing application for the employee pages that you are going to create, but you are going to modify how the data displays just a little.

Note

The reason for using classes and class managers in a Windows forms application is because you maintain the state of the data and it makes it easier for you to keep track of your objects' state. When writing a Web application, there is no (or very little) state persistence that you can directly manage. To that extent, Microsoft has done an excellent job of encapsulating state management within the dataset.

start sidebar
Using Dataset Objects

I have had several people ask me, during the course of writing this book, why I do not use datasets more extensively. After all, they have a pretty incredible form of state management built into them, you can constrain values entered into the fields, and you can display errors in a datagrid just as you did with the ErrorProvider on the forms. You can also bind certain controls for editing specific types of data to a grid and get the same functionality you would on a form (for example, you can set the date/time combo box so that you can use it from within a grid to edit date fields).

There is one reason why I do not use datasets extensively: They do not offer enough control over the data, and I am a data control freak. For many people, the dataset functionality works great, and Microsoft has done an excellent job of creating the dataset to be everything that developers who used Visual Basic 6 and earlier wanted. But there are a couple of things you cannot do with it and a couple of workarounds you need to put in place to make these things work.

As an example of what you cannot do with them, consider business rules. You cannot check values in the dataset granularly against a business rule—for every record you update, you need to extract the information from the dataset, pass it to an object that can check the rules, and return the information to the dataset. In essence you can use the dataset, but you still need to have the classes and all of the business rules written in almost the same way. It also ties the database to each of the other layers much more tightly than a distributed application should be tied. For a two-tier application this is probably perfectly acceptable, but for a distributed application, it is not.

Also, the prepared commands using the CommandBuilder object are extremely bulky, time consuming, and difficult to code.

end sidebar

Add a datagrid to the employees.aspx Web page (do not do anything but drop it on the form). Switch to the code view and edit the Page_Load method so that it is identical to the code in Listing 12-9.

Listing 12-9: The Employees.aspx Page_Load Method

start example
 Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load      Dim objService As New localhost.Service1()      DataGrid1.DataSource = objService.GetAllEmployees      DataGrid1.DataBind()      objService = Nothing End Sub 
end example




Building Client/Server Applications with VB. NET(c) An Example-Driven Approach
Building Client/Server Applications Under VB .NET: An Example-Driven Approach
ISBN: 1590590708
EAN: 2147483647
Year: 2005
Pages: 148
Authors: Jeff Levinson

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net