Showing one record in a form view
A grid shows many rows. A form view shows one record at a time, laid out as an ordinary form.
The pairing
Markup
<asp:SqlDataSource id="oneProduct" runat="server"
ConnectionString="<%$ ConnectionStrings:Shop %>"
SelectCommand="SELECT Id, Name, Price FROM Product WHERE Id = @id">
<SelectParameters>
<asp:QueryStringParameter Name="id" QueryStringField="id" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView id="productView" runat="server"
DataSourceID="oneProduct" DefaultMode="ReadOnly">
<ItemTemplate>
<h2><%# Eval("Name") %></h2>
<p>Price: <%# Eval("Price") %></p>
</ItemTemplate>
</asp:FormView>What to notice
- The query string supplies the identifier that selects the record.
- The item template decides how the record is laid out.
- Eval reads a field from the bound row.
Handle the missing record. If the identifier matches nothing, the form view is simply empty. Show a friendly message rather than a blank panel.
To let the visitor change the record, continue to editing one record.