System.Web.UI.WebControls Namespace
.NET Framework version 2.0
Displays the values of a single record from a data source in a table, where each data row represents a field of the record. The DetailsView control allows you to edit, delete, and insert records.
Visibility |
Constructor |
Parameters |
public |
DetailsView |
( )
|
Visibility |
Name |
Value Type |
Accessibility |
public |
AllowPaging
|
Boolean |
[ Get , Set ] |
public |
AlternatingRowStyle
|
TableItemStyle |
[ Get ] |
public |
AutoGenerateDeleteButton
|
Boolean |
[ Get , Set ] |
public |
AutoGenerateEditButton
|
Boolean |
[ Get , Set ] |
public |
AutoGenerateInsertButton
|
Boolean |
[ Get , Set ] |
public |
AutoGenerateRows
|
Boolean |
[ Get , Set ] |
public |
BackImageUrl
|
String |
[ Get , Set ] |
public |
BottomPagerRow
|
DetailsViewRow |
[ Get ] |
public |
Caption
|
String |
[ Get , Set ] |
public |
CaptionAlign
|
TableCaptionAlign |
[ Get , Set ] |
public |
CellPadding
|
Int32 |
[ Get , Set ] |
public |
CellSpacing
|
Int32 |
[ Get , Set ] |
public |
CommandRowStyle
|
TableItemStyle |
[ Get ] |
public |
CurrentMode
|
DetailsViewMode |
[ Get ] |
public |
DataItem
|
Object |
[ Get ] |
public |
DataItemCount
|
Int32 |
[ Get ] |
public |
DataItemIndex
|
Int32 |
[ Get ] |
public |
DataKey
|
DataKey |
[ Get ] |
public |
DataKeyNames
|
String |
[ Get , Set ] |
public |
DefaultMode
|
DetailsViewMode |
[ Get , Set ] |
public |
DeleteMethod
|
String |
[ Get , Set ] |
public |
EditRowStyle
|
TableItemStyle |
[ Get ] |
public |
EmptyDataRowStyle
|
TableItemStyle |
[ Get ] |
public |
EmptyDataTemplate
|
ITemplate |
[ Get , Set ] |
public |
EmptyDataText
|
String |
[ Get , Set ] |
public |
EnableModelValidation
|
Boolean |
[ Get , Set ] |
public |
EnablePagingCallbacks
|
Boolean |
[ Get , Set ] |
public |
FieldHeaderStyle
|
TableItemStyle |
[ Get ] |
public |
Fields
|
DataControlFieldCollection |
[ Get ] |
public |
FooterRow
|
DetailsViewRow |
[ Get ] |
public |
FooterStyle
|
TableItemStyle |
[ Get ] |
public |
FooterTemplate
|
ITemplate |
[ Get , Set ] |
public |
FooterText
|
String |
[ Get , Set ] |
public |
GridLines
|
GridLines |
[ Get , Set ] |
public |
HeaderRow
|
DetailsViewRow |
[ Get ] |
public |
HeaderStyle
|
TableItemStyle |
[ Get ] |
public |
HeaderTemplate
|
ITemplate |
[ Get , Set ] |
public |
HeaderText
|
String |
[ Get , Set ] |
public |
HorizontalAlign
|
HorizontalAlign |
[ Get , Set ] |
public |
InsertMethod
|
String |
[ Get , Set ] |
public |
InsertRowStyle
|
TableItemStyle |
[ Get ] |
public |
PageCount
|
Int32 |
[ Get ] |
public |
PageIndex
|
Int32 |
[ Get , Set ] |
public |
PagerSettings
|
PagerSettings |
[ Get ] |
public |
PagerStyle
|
TableItemStyle |
[ Get ] |
public |
PagerTemplate
|
ITemplate |
[ Get , Set ] |
public |
Rows
|
DetailsViewRowCollection |
[ Get ] |
public |
RowsGenerator
|
IAutoFieldGenerator |
[ Get , Set ] |
public |
RowStyle
|
TableItemStyle |
[ Get ] |
public |
SelectedValue
|
Object |
[ Get ] |
public |
TopPagerRow
|
DetailsViewRow |
[ Get ] |
public |
UpdateMethod
|
String |
[ Get , Set ] |
Visibility |
Name |
Parameters |
Return Type |
public |
ChangeMode |
(
DetailsViewMode
newMode
)
|
Void
|
protected |
CreateAutoGeneratedRow |
(
AutoGeneratedFieldProperties
fieldProperties
)
|
AutoGeneratedField
|
protected |
CreateAutoGeneratedRows |
(
Object
dataItem
)
|
ICollection
|
protected |
CreateChildControls |
(
IEnumerable
dataSource
,
Boolean
dataBinding
)
|
Int32
|
protected |
CreateControlStyle |
( )
|
Style
|
protected |
CreateDataSourceSelectArguments |
( )
|
DataSourceSelectArguments
|
protected |
CreateFieldSet |
(
Object
dataItem
,
Boolean
useDataSource
)
|
ICollection
|
protected |
CreateRow |
(
Int32
rowIndex
,
DataControlRowType
rowType
,
DataControlRowState
rowState
)
|
DetailsViewRow
|
protected |
CreateTable |
( )
|
Table
|
public |
DataBind |
( )
|
Void
|
public |
DeleteItem |
( )
|
Void
|
protected |
EnsureDataBound |
( )
|
Void
|
protected |
ExtractRowValues |
(
IOrderedDictionary
fieldValues
,
Boolean
includeReadOnlyFields
,
Boolean
includeKeys
)
|
Void
|
protected |
GetCallbackResult |
( )
|
String
|
protected |
GetCallbackScript |
(
IButtonControl
buttonControl
,
String
argument
)
|
String
|
protected |
InitializePager |
(
DetailsViewRow
row
,
PagedDataSource
pagedDataSource
)
|
Void
|
protected |
InitializeRow |
(
DetailsViewRow
row
,
DataControlField
field
)
|
Void
|
public |
InsertItem |
(
Boolean
causesValidation
)
|
Void
|
public |
IsBindableType |
(
Type
type
)
|
Boolean
|
protected |
LoadViewState |
(
Object
savedState
)
|
Void
|
protected |
OnBubbleEvent |
(
Object
source
,
EventArgs
e
)
|
Boolean
|
protected |
OnDataSourceViewChanged |
(
Object
sender
,
EventArgs
e
)
|
Void
|
protected |
OnItemCommand |
(
DetailsViewCommandEventArgs
e
)
|
Void
|
protected |
OnItemCreated |
(
EventArgs
e
)
|
Void
|
protected |
OnItemDeleted |
(
DetailsViewDeletedEventArgs
e
)
|
Void
|
protected |
OnItemDeleting |
(
DetailsViewDeleteEventArgs
e
)
|
Void
|
protected |
OnItemInserted |
(
DetailsViewInsertedEventArgs
e
)
|
Void
|
protected |
OnItemInserting |
(
DetailsViewInsertEventArgs
e
)
|
Void
|
protected |
OnItemUpdated |
(
DetailsViewUpdatedEventArgs
e
)
|
Void
|
protected |
OnItemUpdating |
(
DetailsViewUpdateEventArgs
e
)
|
Void
|
protected |
OnModeChanged |
(
EventArgs
e
)
|
Void
|
protected |
OnModeChanging |
(
DetailsViewModeEventArgs
e
)
|
Void
|
protected |
OnPageIndexChanged |
(
EventArgs
e
)
|
Void
|
protected |
OnPageIndexChanging |
(
DetailsViewPageEventArgs
e
)
|
Void
|
protected |
OnPagePreLoad |
(
Object
sender
,
EventArgs
e
)
|
Void
|
protected |
RaiseCallbackEvent |
(
String
eventArgument
)
|
Void
|
protected |
RaisePostBackEvent |
(
String
eventArgument
)
|
Void
|
protected |
SaveViewState |
( )
|
Object
|
public |
SetPageIndex |
(
Int32
index
)
|
Void
|
protected |
TrackViewState |
( )
|
Void
|
public |
UpdateItem |
(
Boolean
causesValidation
)
|
Void
|
|
The DetailsView control is used to display a single record from a data source in a table, where each field of the record is displayed in a row of the table. It can be used in combination with a GridView control for master-detail scenarios. The DetailsView control supports the following features:
- Binding to data source controls, such as SqlDataSource.
- Built-in inserting capabilities.
- Built-in updating and deleting capabilities.
- Built-in paging capabilities.
- Programmatic access to the DetailsView object model to dynamically set properties, handle events, and so on.
- Customizable appearance through themes and styles.
Each data row in the DetailsView control is created by declaring a field control. Different row field types determine the behavior of the rows in the control. Field controls derive from DataControlField. The following table lists the different row field types that can be used.
Column field type |
Description |
BoundField |
Displays the value of a field in a data source as text. |
ButtonField |
Displays a command button in the DetailsView control. This allows you to display a row with a custom button control, such as an Add or a Remove button. |
CheckBoxField |
Displays a check box in the DetailsView control. This row field type is commonly used to display fields with a Boolean value. |
CommandField |
Displays built-in command buttons to perform edit, insert, or delete operations in the DetailsView control. |
HyperLinkField |
Displays the value of a field in a data source as a hyperlink. This row field type allows you to bind a second field to the hyperlink's URL. |
ImageField |
Displays an image in the DetailsView control. |
TemplateField |
Displays user-defined content for a row in the DetailsView control according to a specified template. This row field type allows you to create a custom row field. |
By default, the AutoGenerateRows property is set to true, which automatically generates a bound row field object for each field of a bindable type in the data source. Valid bindable types are String, DateTime, Decimal, Guid, and the set of primitive types. Each field is then displayed in a row as text, in the order in which each field appears in the data source.
Automatically generating the rows provides a quick and easy way to display every field in the record. However, to make use of the DetailsView control's advanced capabilities you must explicitly declare the row fields to include in the DetailsView control. To declare the row fields, first set the AutoGenerateRows property to false. Next, add opening and closing <Fields> tags between the opening and closing tags of the DetailsView control. Finally, list the row fields that you want to include between the opening and closing <Fields> tags. The row fields specified are added to the Fields collection in the order listed. The Fields collection allows you to programmatically manage the row fields in the DetailsView control.
NOTE: Automatically generated row fields are not added to the Fields collection.
NOTE: Explicitly declared row fields can be displayed in combination with automatically generated row fields. When both are used, explicitly declared row fields are rendered first, followed by the automatically generated row fields.
The DetailsView control can be bound to a data source control, such as SqlDataSource or AccessDataSource, or to any data source that implements the System.Collections.IEnumerable interface, such as System.Data.DataView, System.Collections.ArrayList and System.Collections.Hashtable. Use one of the following methods to bind the DetailsView control to the appropriate data source type:
- To bind to a data source control, set the DataSourceID property of the DetailsView control to the ID value of the data source control. The DetailsView control automatically binds to the specified data source control. This is the preferred method to bind to data.
- To bind to a data source that implements the System.Collections.IEnumerable interface, programmatically set the DataSource property of the DetailsView control to the data source and then call the DataBind method.
For more information on data binding, see Binding to Databases.
This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. ASP.NET provides an input request validation feature to block script and HTML in user input. For more information, see Script Exploits Overview. Validation server controls are also provided to assess user input. For more information, see Validation Server Control Syntax.
The DetailsView control provides built-in capabilities that allow the user to update, delete, insert, and page through items in the control. When the DetailsView control is bound to a data source control, the DetailsView control can take advantage of the data source control's capabilities and provide automatic updating, deleting, inserting, and paging functionality.
NOTE: The DetailsView control can provide support for update, delete, insert, and paging operations with other types of data sources; however, you must provide the implementation for these operations in an appropriate event handler. For more information, see ItemDeleting, ItemInserting, and ItemUpdating.
The DetailsView control can automatically add a CommandField row field with an Edit, Delete, or New button by setting the AutoGenerateEditButton, AutoGenerateDeleteButton, or AutoGenerateInsertButton properties to true, respectively. Unlike the Delete button (which deletes the selected record immediately), when the Edit or New button is clicked, the DetailsView control goes into edit or insert mode, respectively. In edit mode, the Edit button is replaced with an Update and a Cancel button. Input controls that are appropriate for the field's data type (such as a TextBox or a CheckBox control) are displayed with a field's value for the user to modify. Clicking the Update button updates the record in the data source, while clicking the Cancel button abandons any changes. Likewise, in insert mode, the New button is replaced with an Insert and a Cancel button, and empty input controls are displayed for the user to enter the values for the new record.
NOTE: You can also manually define the update, delete, and insert command buttons in a ButtonField, CommandField, or TemplateField row field. The DetailsView control recognizes buttons with the CommandName property set to "Edit", "Update", "Delete", "New", "Insert", or "Cancel"; however, you still must provide the functionality yourself. For more information, see ItemDeleting, ItemInserting, and ItemUpdating.
The DetailsView control provides a paging feature, which allows the user to navigate to other records in the data source. When enabled, page navigation controls are displayed in a pager row. To enable paging, set the AllowPaging property to true. The pager row can be customized using the PagerStyle and PagerSettings properties.
You can customize the appearance of the DetailsView control by setting the style properties for the different parts of the control. The following table lists the different style properties.
Style property |
Description |
AlternatingRowStyle |
The style settings for the alternating data rows in the DetailsView control. When this property is set, the data rows are displayed alternating between the RowStyle settings and the AlternatingRowStyle settings. |
CommandRowStyle |
The style settings for the row containing the built-in command buttons in the DetailsView control. |
EditRowStyle |
The style settings for the data rows when the DetailsView control is in edit mode. |
EmptyDataRowStyle |
The style settings for the empty data row displayed in the DetailsView control when the data source does not contain any records. |
FooterStyle |
The style settings for the footer row of the DetailsView control. |
HeaderStyle |
The style settings for the header row of the DetailsView control. |
InsertRowStyle |
The style settings for the data rows when the DetailsView control is in insert mode. |
PagerStyle |
The style settings for the pager row of the DetailsView control. |
RowStyle |
The style settings for the data rows in the DetailsView control. When the AlternatingRowStyle property is also set, the data rows are displayed alternating between the RowStyle settings and the AlternatingRowStyle settings. |
FieldHeaderStyle |
The style settings for the header column of the DetailsView control. |
For examples illustrating use of this control, see the individual member types of this class. For syntax information, see DetailsView in ASP.NET Syntax for Web Controls.
DetailsView Web Server Control