ASP.NET Web Forms
Adding a DetailsView
Once a suitable data source is in place, a DetailsView can
be dragged and dropped into the web page either in
design view or code view. Rename is suitably, for
example CustomersDetailsView.
Switch to Design view and select "Choose Data Source.
There should be just one data source available in this
case the CustomersDataSource. If the fields do not
appear in the form immediately select Refresh Schema
from the components menu
Select Enable Insert, Edit and Paging. As its names suggests
typically all the fields would be included in the form apart
from the ID field which the user would not normally edit or
even see. Remove it from the list of fields
Editing Fields
Select Edit Fields
and change their properties such as header text to make the
field names more readable. Fields can be moved up or down, and
command fields can be changed from links to buttons or images
(icons). Finally you can automatically format them from preset
colour schemes, or apply styles form your css sheet using the
cssClass property just like GridViews.
Although Edit works first time, clicking on New and filling in suitable
data and then clicking on Insert fails with the following very helpful
error message
The error message is in fact totally misleading. It has nothing to
do with null values. It is in fact to do with an error in the
INSERT query which includes the CustomerID field. ID fields are
typically auto-number which means that they should not be included
in the INSERT query. So edit the XML code and remove the CustomerID
from the query (including one ? which stands for a parameter), and
also remove it from the INSERT Parameters list.
Again we have now implemented all the CRUD database operations
and still No Visual Basic code has yet been written!!!!
There is however amuch more to Web Forms that has not yet been covered
and in particular Data Validation and other field types such as
dropdown lists, checkboxes and calendars. There is also the
question of user names, passwords and authentication to ensure
that only admin people can access the admin pages.