You can customize the
![]() |
---|
For more information on data-binding expressions, see |
Display Templates
The primary display template for the FormView control is the
Visual BasicВ | ![]() |
---|---|
<asp:FormView ID="FormView1" DataSourceID="SqlDataSource1" DataKeyNames="ProductID" RunAt="server"> <ItemTemplate> <table> <tr><td align=right><B>Product ID:</B></td> <td><%# Eval("ProductID") %></td></tr> <tr><td align=right><B>Product Name:</B></td> <td><%# Eval("ProductName") %></td></tr> <tr><td align=right><B>Category ID:</B></td> <td><%# Eval("CategoryID") %></td></tr> <tr><td align=right><B>Quantity Per Unit:</B></td><td><%# Eval("QuantityPerUnit") %></td></tr> <tr><td align=right><B>Unit Price:</B></td> <td><%# Eval("UnitPrice") %></td></tr> </table> </ItemTemplate> </asp:FormView> |
C#В | ![]() |
---|---|
<asp:FormView ID="FormView1" DataSourceID="SqlDataSource1" DataKeyNames="ProductID" RunAt="server"> <ItemTemplate> <table> <tr><td align=right><B>Product ID:</B></td> <td><%# Eval("ProductID") %></td></tr> <tr><td align=right><B>Product Name:</B></td> <td><%# Eval("ProductName") %></td></tr> <tr><td align=right><B>Category ID:</B></td> <td><%# Eval("CategoryID") %></td></tr> <tr><td align=right><B>Quantity Per Unit:</B></td><td><%# Eval("QuantityPerUnit") %></td></tr> <tr><td align=right><B>Unit Price:</B></td> <td><%# Eval("UnitPrice") %></td></tr> </table> </ItemTemplate> </asp:FormView> |
The ItemTemplate template can include
The other display templates that you can use with the FormView control are the
Edit and Insert Templates
You can use the
Visual BasicВ | ![]() |
---|---|
<asp:sqlDataSource ID="EmployeeDetailsSqlDataSource" SelectCommand="SELECT EmployeeID, LastName, FirstName FROM Employees WHERE EmployeeID = @EmpID" InsertCommand="INSERT INTO Employees(LastName, FirstName) VALUES (@LastName, @FirstName); SELECT @EmpID = SCOPE_IDENTITY()" UpdateCommand="UPDATE Employees SET LastName=@LastName, FirstName=@FirstName WHERE EmployeeID=@EmployeeID" DeleteCommand="DELETE Employees WHERE EmployeeID=@EmployeeID" ConnectionString="<%$ ConnectionStrings:NorthwindConnection %>" OnInserted="EmployeeDetailsSqlDataSource_OnInserted" RunAt="server"> <SelectParameters> <asp:Parameter Name="EmpID" Type="Int32" DefaultValue="0" /> </SelectParameters> <InsertParameters> <asp:Parameter Name="EmpID" Direction="Output" Type="Int32" DefaultValue="0" /> </InsertParameters> </asp:sqlDataSource> |
C#В | ![]() |
---|---|
<asp:sqlDataSource ID="EmployeeDetailsSqlDataSource" SelectCommand="SELECT EmployeeID, LastName, FirstName FROM Employees WHERE EmployeeID = @EmpID" InsertCommand="INSERT INTO Employees(LastName, FirstName) VALUES (@LastName, @FirstName); SELECT @EmpID = SCOPE_IDENTITY()" UpdateCommand="UPDATE Employees SET LastName=@LastName, FirstName=@FirstName WHERE EmployeeID=@EmployeeID" DeleteCommand="DELETE Employees WHERE EmployeeID=@EmployeeID" ConnectionString="<%$ ConnectionStrings:NorthwindConnection %>" OnInserted="EmployeeDetailsSqlDataSource_OnInserted" RunAt="server"> <SelectParameters> <asp:Parameter Name="EmpID" Type="Int32" DefaultValue="0" /> </SelectParameters> <InsertParameters> <asp:Parameter Name="EmpID" Direction="Output" Type="Int32" DefaultValue="0" /> </InsertParameters> </asp:sqlDataSource> |
![]() |
---|
When you use a |
The EditItemTemplate template is loaded when users click a command button with a CommandName value of Edit. You can add a LinkButton command button with a CommandName of Update to take the current bound values and send them to the data source control for update. You can add a LinkButton command button with a CommandName of Cancel to discard the current bound values and return the FormView control to read-only mode and load the ItemTemplate template.
The InsertItemTemplate template is loaded when users click a command button with a CommandName of New. You can add a LinkButton command button with a CommandName of Insert to send values for a new record to the data source control. You can add a LinkButton command button with a CommandName of Cancel to discard the new values and return the FormView to read-only mode and load the ItemTemplate template.
For an example of using the FormView control to edit data, see Modifying Data Using a FormView Web Server Control.
Data Paging Template
In the FormView control, a page of data is a single bound record. If you set the
For an example of a PagerTemplate template for a FormView control, see Paging in a FormView Web Server Control.