[download sample app]
Currently, there are a few admin pages for entering data for this sample application. The pages include AddEditPlayers.aspx, AddEditPositions.aspx, AddEditStats.aspx, and AddEditTeams.aspx. Here I will cover the basics of how these all come together.
To start learning the new "gee whizz" features of ASP.NET 2.0, I started out by using the SqlDataSource to see how easily I could generate admin screens. I found that it can be done quickly.
For instance, on AddEditPositions.aspx, everything but Insert is handled through drag and drop and then setting the appropriate properties. When I created the SqlDataSource for the Positions table, I specify the fields, and the SqlDataSource automatically generates the insert, update, select, and delete statements.
These appear to encapsulate the adapter found in Visual Studio 2002 and 2003 in a one-step data source. Also, you can configure this to automatically create and use a connection string from your config file, a handy feature.
Using the Gridview control, click on the smart-tag arrow, and select Configure Data Source. Follow the wizard, selecting the connection information, then specify the fields to select from the table. Click on the Advanced Options button to set the wizard to automatically generate the insert, update, and delete statements.
To insert a new position, there are two text boxes for the position name, description, and an Add button. Below is a sample of the actual code used to insert the data:
SqlDataSource1.InsertParameters["Position"].DefaultValue = txtPosition.Text;
SqlDataSource1.InsertParameters["Description"].DefaultValue = txtDescription.Text;
In this case it takes 3 lines to insert a record. While I don't think my production applications will use this type of approach for everything, for quick admin pages not used by many, this is a quick way to get the functionality.