Details View server control is used to display, delete, insert or edit a single record from data source. More about Form View control you can read in Form View Control: Step by Step tutorial. After we created Sql Data Source control, we need to associate it with Details View control.
Details View control is often used in master/detail scenario with Grid View control. To work with records, first we need to connect Details View control with some data source. You can do that in design view, like on next image: Also, you can do this if you set Data Source ID property of Details View control to the name of your data source control. Sql Data Source control above uses a database with Products and Categories tables.
NET 2.0 or later we can use specialized Details View and Form View controls. If you only need to show record in read-only mode, your data source control needs only Select command.
Here is a markup code for this Sql Data Source control: ="SELECT Products. Of course, you can use your own existing table, just adopt Sql Data Source commands to suit your table structure.
Category Name FROM Products INNER JOIN Categories ON Products. ID ORDER BY Product ID" This data source contains commands for all four basic operations: Select, Update, Insert and Delete.
Run the example and Details View control will show first record, similar to the next image: Before using an example you need to set Data Key Names property of Details View control to the name of table primary key column.
In our case table primary key column is named "Product ID".
Now, you can start an example again and joy in new features.
Test paging, updating, deleting and inserting a new record to see how it works.You'll see new buttons Edit, Delete and New link buttons.Note that we did all this without writing single line of C# or VB. Output should look similar to image bellow: Now, the example is completely functional, although it looks ugly.For example, instead of showing an URL of image, it would be better to show image itself, instead of product url it will be better to show clickable link etc.By default, Details View control has Auto Generate Rows property set to true.That means that all fields will be generated at run time, depending of what fields your data source contains.