FormViewRow Class
Represents a row within a FormView control.
Assembly: System.Web (in System.Web.dll)
The FormViewRow class is used to represent an individual row in a FormView control. Each row in the FormView control has a designated row type. The following table lists the different row types.
Row type | Description |
|---|---|
DataControlRowType.DataRow | The data row in the FormView control. |
DataControlRowType.EmptyDataRow | The empty data row in the FormView control. The empty data row is displayed in a FormView control when there are no records to display. |
DataControlRowType.Footer | The footer row in the FormView control. |
DataControlRowType.Header | The header row in the FormView control. |
DataControlRowType.Pager | A pager row in the FormView control. |
To determine the row type of a FormViewRow object, use the RowType property. A FormViewRow object also has a state associated with it. The state can be a bitwise combination of the values in the following table.
State value | Description |
|---|---|
DataControlRowState.Edit | The FormViewRow object is in edit mode. |
DataControlRowState.Insert | The FormViewRow object is in insert mode. |
DataControlRowState.Normal | The FormViewRow object is in its normal (default) state. |
DataControlRowState.Selected | The FormViewRow object is selected. |
To determine the state of a FormViewRow object, use the RowState property.
The FormView control displays the contents of its ItemTemplate property in a data row. To access the data row, use the Row property. To determine the index of the current data item in the data source, use the ItemIndex property.
You can access the individual cells of the FormViewRow object by using the Cells property. If a cell contains controls, you can retrieve a control from the cell by using one of the following methods:
Use the Controls collection of the cell to retrieve the control at a specific index.
Use the FindControl method of the cell to retrieve the control, if the control has its ID property set. This is the preferred method to retrieve a control from a cell.
For a list of initial property values for an instance of the FormViewRow class, see the FormViewRow constructor.
The following example demonstrates how to retrieve an Image control from the FormViewRow object that represents the item row. The Image controls are declared in the edit and item templates.
<%@ page language="C#" %> <%@ import namespace="System.Data" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> void EmployeeFormView_DataBound(Object sender, EventArgs e) { // Use the Row property to retrieve the data row from // the FormView control. FormViewRow row = EmployeeFormView.Row; // Get the data item bound to the FormView control. DataRowView rowView = (DataRowView)EmployeeFormView.DataItem; // Retrieve the Image control from the appropriate template // based on the current mode. Image employeePhoto = null; switch(EmployeeFormView.CurrentMode) { case FormViewMode.ReadOnly: employeePhoto = (Image)row.FindControl("EmployeeImage"); break; case FormViewMode.Edit: employeePhoto = (Image)row.FindControl("EmployeeEditImage"); break; default: // Do nothing. break; } // Set the ToolTip property of the employee's photo. if (employeePhoto != null) { employeePhoto.ToolTip = rowView["FirstName"].ToString() + " " + rowView["LastName"].ToString(); } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>FormViewRow Example</title> </head> <body> <form id="form1" runat="server"> <h3>FormViewRow Example</h3> <asp:formview id="EmployeeFormView" datasourceid="EmployeeSource" allowpaging="true" datakeynames="EmployeeID" emptydatatext="No employees found." ondatabound="EmployeeFormView_DataBound" runat="server"> <itemtemplate> <table> <tr> <td rowspan="6"> <asp:image id="EmployeeImage" imageurl='<%# Eval("PhotoPath") %>' runat="server"/> </td> <td colspan="2"> </td> </tr> <tr> <td> <b>Name:</b> </td> <td> <%# Eval("FirstName") %> <%# Eval("LastName") %> </td> </tr> <tr> <td> <b>Title:</b> </td> <td> <%# Eval("Title") %> </td> </tr> <tr style="height:150" valign="top"> <td> <b>Address:</b> </td> <td> <%# Eval("Address") %><br/> <%# Eval("City") %> <%# Eval("Region") %> <%# Eval("PostalCode") %><br/> <%# Eval("Country") %> </td> </tr> <tr> <td colspan="2"> <asp:linkbutton id="Edit" text="Edit" commandname="Edit" runat="server"/> </td> </tr> </table> </itemtemplate> <edititemtemplate> <table> <tr> <td rowspan="6"> <asp:image id="EmployeeEditImage" imageurl='<%# Eval("PhotoPath") %>' alternatetext='<%# Eval("LastName") %>' runat="server"/> </td> <td colspan="2"> </td> </tr> <tr> <td> <b><asp:Label runat="server" AssociatedControlID="FirstNameUpdateTextBox" Text="Name" />:</b> </td> <td> <asp:textbox id="FirstNameUpdateTextBox" text='<%# Bind("FirstName") %>' accesskey="n" tabindex="1" runat="server"/> <asp:textbox id="LastNameUpdateTextBox" text='<%# Bind("LastName") %>' accesskey="l" tabindex="2" runat="server"/> </td> </tr> <tr> <td> <b><asp:Label runat="server" AssociatedControlID="TitleUpdateTextBox" Text="Title" />:</b> </td> <td> <asp:textbox id="TitleUpdateTextBox" text='<%# Bind("Title") %>' accesskey="t" tabindex="3" runat="server"/> </td> </tr> <tr> <b><asp:Label runat="server" AssociatedControlID="HireDateUpdateTextBox" Text="Hire Date" />:</b> <td> <asp:textbox id="HireDateUpdateTextBox" text='<%# Bind("HireDate", "{0:d}") %>' accesskey="h" tabindex="4" runat="server" /> </td> </tr> <tr style="height:150" valign="top"> <td> <b><asp:Label runat="server" AssociatedControlID="AddressUpdateTextBox" Text="Address" />:</b> </td> <td> <asp:textbox id="AddressUpdateTextBox" text='<%# Bind("Address") %>' accesskey="a" tabindex="5" runat="server"/> <br/> <asp:textbox id="CityUpdateTextBox" text='<%# Bind("City") %>' accesskey="c" tabindex="6" runat="server"/> <asp:textbox id="RegionUpdateTextBox" text='<%# Bind("Region") %>' width="40" accesskey="r" tabindex="7" runat="server"/> <asp:textbox id="PostalCodeUpdateTextBox" text='<%# Bind("PostalCode") %>' width="60" accesskey="p" tabindex="8" runat="server"/> <br/> <asp:textbox id="CountryUpdateTextBox" text='<%# Bind("Country") %>' accesskey="u" tabindex="9" runat="server"/> </td> </tr> <tr> <td colspan="2"> <asp:linkbutton id="UpdateButton" text="Update" tabindex="10" commandname="Update" runat="server"/> <asp:linkbutton id="CancelButton" text="Cancel" tabindex="11" commandname="Cancel" runat="server"/> </td> </tr> </table> </edititemtemplate> </asp:formview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="EmployeeSource" selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [Address], [City], [Region], [PostalCode], [Country], [HireDate], [PhotoPath] From [Employees]" updatecommand="Update [Employees] Set [LastName]=@LastName, [FirstName]=@FirstName, [Title]=@Title, [Address]=@Address, [City]=@City, [Region]=@Region, [PostalCode]=@PostalCode, [Country]=@Country Where [EmployeeID]=@EmployeeID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
- AspNetHostingPermission
For operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission
For operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.TableRow
System.Web.UI.WebControls.FormViewRow
System.Web.UI.WebControls.FormViewPagerRow
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.