.NET Framework Class Library ListViewDataItem Class Represents an individual data item in a ListView control.

Inheritance Hierarchy
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web.Extensions (in System.Web.Extensions.dll)

Syntax
Public Class ListViewDataItem _
Inherits ListViewItem
public class ListViewDataItem : ListViewItem
public ref class ListViewDataItem : public ListViewItem
type ListViewDataItem =
class
inherit ListViewItem
end
The ListViewDataItem type exposes the following members.

Constructors

Properties

Methods
|
| Name | Description |
|---|
.gif) | AddedControl | Called after a child control is added to the Controls collection of the Control object. (Inherited from Control.) | .gif) | AddParsedSubObject | Notifies the server control that an element, either XML or HTML, was parsed, and adds the element to the server control's ControlCollection object. (Inherited from Control.) | .gif) | ApplyStyleSheetSkin | Applies the style properties defined in the page style sheet to the control. (Inherited from Control.) | .gif) | BuildProfileTree | Infrastructure. Gathers information about the server control and delivers it to the Trace property to be displayed when tracing is enabled for the page. (Inherited from Control.) | .gif) | ClearCachedClientID | Infrastructure. Sets the cached ClientID value to nullNothingnullptra null reference (Nothing in Visual Basic). (Inherited from Control.) | .gif) | ClearChildControlState | Deletes the control-state information for the server control's child controls. (Inherited from Control.) | .gif) | ClearChildState | Deletes the view-state and control-state information for all the server control's child controls. (Inherited from Control.) | .gif) | ClearChildViewState | Deletes the view-state information for all the server control's child controls. (Inherited from Control.) | .gif) | ClearEffectiveClientIDMode | Infrastructure. Sets the ClientIDMode property of the current control instance and of any child controls to Inherit. (Inherited from Control.) | .gif) | CreateChildControls | Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. (Inherited from Control.) | .gif) | CreateControlCollection | Creates a new ControlCollection object to hold the child controls (both literal and server) of the server control. (Inherited from Control.) | .gif) | DataBind()()() | Binds a data source to the invoked server control and all its child controls. (Inherited from Control.) | .gif) | DataBind(Boolean) | Binds a data source to the invoked server control and all its child controls with an option to raise the DataBinding event. (Inherited from Control.) | .gif) | DataBindChildren | Binds a data source to the server control's child controls. (Inherited from Control.) | .gif) | Dispose | Enables a server control to perform final clean up before it is released from memory. (Inherited from Control.) | .gif) | EnsureChildControls | Determines whether the server control contains child controls. If it does not, it creates child controls. (Inherited from Control.) | .gif) | EnsureID | Creates an identifier for controls that do not have an identifier assigned. (Inherited from Control.) | .gif) | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | .gif) | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | .gif) | FindControl(String) | Searches the current naming container for a server control with the specified id parameter. (Inherited from Control.) | .gif) | FindControl(String, Int32) | Infrastructure. Searches the current naming container for a server control with the specified id and an integer, specified in the pathOffset parameter, which aids in the search. You should not override this version of the FindControl method. (Inherited from Control.) | .gif) | Focus | Sets input focus to a control. (Inherited from Control.) | .gif) | GetDesignModeState | Infrastructure. Gets design-time data for a control. (Inherited from Control.) | .gif) | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | .gif) | GetRouteUrl(Object) | Gets the URL that corresponds to a set of route parameters. (Inherited from Control.) | .gif) | GetRouteUrl(RouteValueDictionary) | Gets the URL that corresponds to a set of route parameters. (Inherited from Control.) | .gif) | GetRouteUrl(String, Object) | Gets the URL that corresponds to a set of route parameters and a route name. (Inherited from Control.) | .gif) | GetRouteUrl(String, RouteValueDictionary) | Gets the URL that corresponds to a set of route parameters and a route name. (Inherited from Control.) | .gif) | GetType | Gets the Type of the current instance. (Inherited from Object.) | .gif) | GetUniqueIDRelativeTo | Returns the prefixed portion of the UniqueID property of the specified control. (Inherited from Control.) | .gif) | HasControls | Determines if the server control contains any child controls. (Inherited from Control.) | .gif) | HasEvents | Returns a value indicating whether events are registered for the control or any child controls. (Inherited from Control.) | .gif) | IsLiteralContent | Infrastructure. Determines if the server control holds only literal content. (Inherited from Control.) | .gif) | LoadControlState | Restores control-state information from a previous page request that was saved by the SaveControlState method. (Inherited from Control.) | .gif) | LoadViewState | Restores view-state information from a previous page request that was saved by the SaveViewState method. (Inherited from Control.) | .gif) | MapPathSecure | Retrieves the physical path that a virtual path, either absolute or relative, maps to. (Inherited from Control.) | .gif) | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | .gif) | OnBubbleEvent | Determines whether to pass an event up the page's ASP.NET server control hierarchy. (Overrides ListViewItem..::.OnBubbleEvent(Object, EventArgs).) | .gif) | OnDataBinding | Raises the DataBinding event. (Inherited from Control.) | .gif) | OnInit | Raises the Init event. (Inherited from Control.) | .gif) | OnLoad | Raises the Load event. (Inherited from Control.) | .gif) | OnPreRender | Raises the PreRender event. (Inherited from Control.) | .gif) | OnUnload | Raises the Unload event. (Inherited from Control.) | .gif) | OpenFile | Gets a Stream used to read a file. (Inherited from Control.) | .gif) | RaiseBubbleEvent | Assigns any sources of the event and its information to the control's parent. (Inherited from Control.) | .gif) | RemovedControl | Called after a child control is removed from the Controls collection of the Control object. (Inherited from Control.) | .gif) | Render | Sends server control content to a provided HtmlTextWriter object, which writes the content to be rendered on the client. (Inherited from Control.) | .gif) | RenderChildren | Outputs the content of a server control's children to a provided HtmlTextWriter object, which writes the content to be rendered on the client. (Inherited from Control.) | .gif) | RenderControl(HtmlTextWriter) | Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled. (Inherited from Control.) | .gif) | RenderControl(HtmlTextWriter, ControlAdapter) | Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object. (Inherited from Control.) | .gif) | ResolveAdapter | Gets the control adapter responsible for rendering the specified control. (Inherited from Control.) | .gif) | ResolveClientUrl | Gets a URL that can be used by the browser. (Inherited from Control.) | .gif) | ResolveUrl | Converts a URL into one that is usable on the requesting client. (Inherited from Control.) | .gif) | SaveControlState | Saves any server control state changes that have occurred since the time the page was posted back to the server. (Inherited from Control.) | .gif) | SaveViewState | Saves any server control view-state changes that have occurred since the time the page was posted back to the server. (Inherited from Control.) | .gif) | SetDesignModeState | Sets design-time data for a control. (Inherited from Control.) | .gif) | SetRenderMethodDelegate | Infrastructure. Assigns an event handler delegate to render the server control and its content into its parent control. (Inherited from Control.) | .gif) | ToString | Returns a string that represents the current object. (Inherited from Object.) | .gif) | TrackViewState | Causes tracking of view-state changes to the server control so they can be stored in the server control's StateBag object. This object is accessible through the Control..::.ViewState property. (Inherited from Control.) | Top

Extension Methods

Explicit Interface Implementations
|
| Name | Description |
|---|
.gif) .gif) | IControlBuilderAccessor..::.ControlBuilder | For a description of this member, see IControlBuilderAccessor..::.ControlBuilder. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.GetDesignModeState | For a description of this member, see IControlDesignerAccessor..::.GetDesignModeState. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetDesignModeState | For a description of this member, see IControlDesignerAccessor..::.SetDesignModeState. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetOwnerControl | Infrastructure. For a description of this member, see IControlDesignerAccessor..::.SetOwnerControl. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.UserData | For a description of this member, see IControlDesignerAccessor..::.UserData. (Inherited from Control.) | .gif) .gif) | IDataBindingsAccessor..::.DataBindings | For a description of this member, see IDataBindingsAccessor..::.DataBindings. (Inherited from Control.) | .gif) .gif) | IDataBindingsAccessor..::.HasDataBindings | For a description of this member, see IDataBindingsAccessor..::.HasDataBindings. (Inherited from Control.) | .gif) .gif) | IExpressionsAccessor..::.Expressions | For a description of this member, see IExpressionsAccessor..::.Expressions. (Inherited from Control.) | .gif) .gif) | IExpressionsAccessor..::.HasExpressions | For a description of this member, see IExpressionsAccessor..::.HasExpressions. (Inherited from Control.) | .gif) .gif) | IParserAccessor..::.AddParsedSubObject | For a description of this member, see IParserAccessor..::.AddParsedSubObject. (Inherited from Control.) | Top

Remarks
The ListViewDataItem class represents an individual data item in a ListView control. A data item usually corresponds to a record in a data source object. The class derives from the ListViewItem class. Each item in the ListView control has a designated item type that is represented by the ItemType property. When the item type is ListViewItemType..::.DataItem, you can use the ListViewDataItem class to get more information about the item. The ListView control stores data items in the Items collection. To determine the index of a ListViewDataItem object in the Items collection, use the DisplayIndex property. To determine the index of the data item in the underlying data source, use the DataItemIndex property. The difference between these index properties is that DisplayIndex represents the position of the data item in the current page, whereas DataItemIndex is based on the page offset. If the paging functionality is not enabled in the ListView control by using a DataPager control, these two properties will contain the same value. You can access the properties of the underlying data object by using the DataItem property. The DataItem property is available only during and after the ItemDataBound event of a ListView control. For a list of initial property values for an instance of the ListViewDataItem class, see the ListViewDataItem constructor.

Examples
The following example shows how to use a ListViewDataItem object to retrieve a field value from an item in the ListView control. Security Note |
|---|
This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview. |
<%@ Page Language="VB" %>
<%@ 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">
Protected Sub ContactsListView_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs)
'Verify there is an item being edited.
If ContactsListView.EditIndex >= 0 Then
'Get the item object.
Dim dataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
' Check for an item in edit mode.
If dataItem.DisplayIndex = ContactsListView.EditIndex Then
' Preselect the DropDownList control with the Title value
' for the current item.
' Retrieve the underlying data item. In this example
' the underlying data item is a DataRowView object.
Dim rowView As DataRowView = CType(dataItem.DataItem, DataRowView)
' Retrieve the Title value for the current item.
Dim title As String = rowView("Title").ToString()
' Retrieve the DropDownList control from the current row.
Dim list As DropDownList = CType(dataItem.FindControl("TitlesList"), DropDownList)
' Find the ListItem object in the DropDownList control with the
' title value and select the item.
Dim item As ListItem = list.Items.FindByText(title)
list.SelectedIndex = list.Items.IndexOf(item)
End If
End If
End Sub
Sub ContactsListView_ItemUpdating(ByVal sender As Object, ByVal e As ListViewUpdateEventArgs)
' Retrieve the row being edited.
Dim item As ListViewItem = ContactsListView.Items(ContactsListView.EditIndex)
' Retrieve the DropDownList control from the row.
Dim list As DropDownList = CType(item.FindControl("TitlesList"), DropDownList)
' Add the selected value of the DropDownList control to
' the NewValues collection. The NewValues collection is
' passed to the data source control, which then updates the
' data source.
e.NewValues("Title") = list.SelectedValue
End Sub 'ContactsListView_ItemUpdating
</script>
<html >
<head id="Head1" runat="server">
<title>ListView DataItem Example</title>
<link type="text/css" rel="stylesheet" href="StyleSheet.css" />
</head>
<body>
<form id="form1" runat="server">
<h3>ListViewDataItem Example</h3>
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
DataKeyNames="ContactID"
OnItemUpdating="ContactsListView_ItemUpdating"
OnItemDataBound="ContactsListView_ItemDataBound"
runat="server" >
<LayoutTemplate>
<table cellpadding="2" runat="server" id="tblContacts" width="640px">
<tr runat="server" id="itemPlaceholder" />
</table>
<asp:DataPager runat="server" ID="ContactsDataPager" PageSize="12">
<Fields>
<asp:NextPreviousPagerField
ShowFirstPageButton="true" ShowLastPageButton="true"
FirstPageText="|<< " LastPageText=" >>|"
NextPageText=" > " PreviousPageText=" < " />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<tr class="DataItem" runat="server">
<td>
<asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" />
</td>
<td>
<asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
</td>
<td>
<asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
</td>
<td>
<asp:Label ID="TitleLabel" runat="server" Text='<%#Eval("Title", "{0:d}") %>' />
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr class="EditItem">
<td>
<asp:LinkButton ID="UpdateButton" runat="server"
CommandName="Update" Text="Update" /><br />
<asp:LinkButton ID="CancelButton" runat="server"
CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label runat="server" ID="FirstNameLabel"
AssociatedControlID="FirstNameTextBox" Text="First Name:"/>
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%#Bind("FirstName") %>' MaxLength="50" />
</td>
<td>
<asp:Label runat="server" ID="LastNameLabel"
AssociatedControlID="LastNameTextBox" Text="Last Name:" />
<asp:TextBox ID="LastNameTextBox" runat="server"
Text='<%#Bind("LastName") %>' MaxLength="50" /><br />
</td>
<td>
<asp:Label runat="server" ID="TitleLabel"
AssociatedControlID="TitlesList" Text="Title:"/>
<asp:DropDownList ID="TitlesList"
DataSourceID="TitlesSqlDataSource"
DataTextField="Title"
runat="server">
</asp:DropDownList>
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="TitlesSqlDataSource"
SelectCommand="SELECT Distinct [Title] FROM Person.Contact ORDER BY [Title]"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
runat="server">
</asp:SqlDataSource>
<asp:SqlDataSource ID="ContactsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT [ContactID], [FirstName], [LastName], [Title] FROM Person.Contact"
UpdateCommand="UPDATE Person.Contact
SET FirstName = @FirstName, LastName = @LastName, Title = @Title
WHERE ContactID = @ContactID">
<UpdateParameters>
<asp:Parameter ConvertEmptyStringToNull="true" Name="Title" />
</UpdateParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
<%@ 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">
protected void ContactsListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
//Verify there is an item being edited.
if (ContactsListView.EditIndex >= 0)
{
//Get the item object.
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
// Check for an item in edit mode.
if (dataItem.DisplayIndex == ContactsListView.EditIndex)
{
// Preselect the DropDownList control with the Title value
// for the current item.
// Retrieve the underlying data item. In this example
// the underlying data item is a DataRowView object.
DataRowView rowView = (DataRowView)dataItem.DataItem;
// Retrieve the Title value for the current item.
String title = rowView["Title"].ToString();
// Retrieve the DropDownList control from the current row.
DropDownList list = (DropDownList)dataItem.FindControl("TitlesList");
// Find the ListItem object in the DropDownList control with the
// title value and select the item.
ListItem item = list.Items.FindByText(title);
list.SelectedIndex = list.Items.IndexOf(item);
}
}
}
void ContactsListView_ItemUpdating(Object sender, ListViewUpdateEventArgs e)
{
// Retrieve the row being edited.
ListViewItem item = ContactsListView.Items[ContactsListView.EditIndex];
// Retrieve the DropDownList control from the row.
DropDownList list = (DropDownList)item.FindControl("TitlesList");
// Add the selected value of the DropDownList control to
// the NewValues collection. The NewValues collection is
// passed to the data source control, which then updates the
// data source.
e.NewValues["Title"] = list.SelectedValue;
}
</script>
<html >
<head id="Head1" runat="server">
<title>ListView DataItem Example</title>
<link type="text/css" rel="stylesheet" href="StyleSheet.css" />
</head>
<body>
<form id="form1" runat="server">
<h3>ListViewDataItem Example</h3>
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
DataKeyNames="ContactID"
OnItemUpdating="ContactsListView_ItemUpdating"
OnItemDataBound="ContactsListView_ItemDataBound"
runat="server" >
<LayoutTemplate>
<table cellpadding="2" runat="server" id="tblContacts" width="640px">
<tr runat="server" id="itemPlaceholder" />
</table>
<asp:DataPager runat="server" ID="ContactsDataPager" PageSize="12">
<Fields>
<asp:NextPreviousPagerField
ShowFirstPageButton="true" ShowLastPageButton="true"
FirstPageText="|<< " LastPageText=" >>|"
NextPageText=" > " PreviousPageText=" < " />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<tr class="DataItem" runat="server">
<td>
<asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" />
</td>
<td>
<asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
</td>
<td>
<asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
</td>
<td>
<asp:Label ID="TitleLabel" runat="server" Text='<%#Eval("Title", "{0:d}") %>' />
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr class="EditItem">
<td>
<asp:LinkButton ID="UpdateButton" runat="server"
CommandName="Update" Text="Update" /><br />
<asp:LinkButton ID="CancelButton" runat="server"
CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label runat="server" ID="FirstNameLabel"
AssociatedControlID="FirstNameTextBox" Text="First Name:"/>
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%#Bind("FirstName") %>' MaxLength="50" />
</td>
<td>
<asp:Label runat="server" ID="LastNameLabel"
AssociatedControlID="LastNameTextBox" Text="Last Name:" />
<asp:TextBox ID="LastNameTextBox" runat="server"
Text='<%#Bind("LastName") %>' MaxLength="50" /><br />
</td>
<td>
<asp:Label runat="server" ID="TitleLabel"
AssociatedControlID="TitlesList" Text="Title:"/>
<asp:DropDownList ID="TitlesList"
DataSourceID="TitlesSqlDataSource"
DataTextField="Title"
runat="server">
</asp:DropDownList>
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="TitlesSqlDataSource"
SelectCommand="SELECT Distinct [Title] FROM Person.Contact ORDER BY [Title]"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
runat="server">
</asp:SqlDataSource>
<asp:SqlDataSource ID="ContactsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT [ContactID], [FirstName], [LastName], [Title] FROM Person.Contact"
UpdateCommand="UPDATE Person.Contact
SET FirstName = @FirstName, LastName = @LastName, Title = @Title
WHERE ContactID = @ContactID">
<UpdateParameters>
<asp:Parameter ConvertEmptyStringToNull="true" Name="Title" />
</UpdateParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

Version Information
.NET FrameworkSupported in: 4, 3.5

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also
|
Bibliothèque de classes .NET Framework ListViewDataItem, classe Représente un élément de données individuel dans un contrôle ListView.

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web.Extensions (dans System.Web.Extensions.dll)

Syntaxe
Public Class ListViewDataItem _
Inherits ListViewItem
public class ListViewDataItem : ListViewItem
public ref class ListViewDataItem : public ListViewItem
type ListViewDataItem =
class
inherit ListViewItem
end
Le type ListViewDataItem expose les membres suivants.

Constructeurs

Méthodes
|
| Nom | Description |
|---|
.gif) | AddedControl | Appelée après l'ajout d'un contrôle enfant à la collection Controls de l'objet Control. (Hérité de Control.) | .gif) | AddParsedSubObject | Avertit le contrôle serveur qu'un élément XML ou HTML a été analysé et l'ajoute à l'objet ControlCollection du contrôle serveur. (Hérité de Control.) | .gif) | ApplyStyleSheetSkin | Applique les propriétés de style définies dans la feuille de style de la page au contrôle. (Hérité de Control.) | .gif) | BuildProfileTree | Infrastructure. Collecte des informations sur le contrôle serveur et les livre à la propriété Trace à afficher lorsque le traçage est activé pour la page. (Hérité de Control.) | .gif) | ClearCachedClientID | Infrastructure. Affecte à la valeur ClientID mise en cache la valeur nullNothingnullptrune référence null (Nothing en Visual Basic). (Hérité de Control.) | .gif) | ClearChildControlState | Supprime les informations sur l'état du contrôle des contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearChildState | Supprime les informations sur l'état d'affichage et sur l'état du contrôle de tous les contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearChildViewState | Supprime les informations d'état d'affichage de tous les contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearEffectiveClientIDMode | Infrastructure. Affecte la valeur Inherit à la propriété ClientIDMode de l'instance de contrôle actuelle et de tous contrôles enfants. (Hérité de Control.) | .gif) | CreateChildControls | Appelé par l'infrastructure de page ASP.NET pour avertir les contrôles serveur qui utilisent une implémentation basée sur la composition qu'ils doivent créer tous les contrôles enfants qu'ils contiennent en préparation de la publication ou du rendu. (Hérité de Control.) | .gif) | CreateControlCollection | Crée un nouvel objet ControlCollection pour contenir les contrôles enfants (littéraux et serveur) du contrôle serveur. (Hérité de Control.) | .gif) | DataBind()()() | Lie une source de données au contrôle serveur appelé et à tous ses contrôles enfants. (Hérité de Control.) | .gif) | DataBind(Boolean) | Lie une source de données au contrôle serveur appelé et tous ses contrôles enfants avec une option pour déclencher l'événement DataBinding. (Hérité de Control.) | .gif) | DataBindChildren | Lie une source de données aux contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | Dispose | Permet à un contrôle serveur d'effectuer le nettoyage final avant qu'il soit libéré de la mémoire. (Hérité de Control.) | .gif) | EnsureChildControls | Détermine si le contrôle serveur contient des contrôles enfants. S'il ne contient pas de contrôles enfants, il en crée. (Hérité de Control.) | .gif) | EnsureID | Crée un identificateur pour les contrôles auxquels aucun identificateur n'est assigné. (Hérité de Control.) | .gif) | Equals(Object) | Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.) | .gif) | Finalize | Autorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de netto***ge avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.) | .gif) | FindControl(String) | Recherche un contrôle serveur possédant le paramètre id spécifié dans le conteneur d'attribution de noms actuel. (Hérité de Control.) | .gif) | FindControl(String, Int32) | Infrastructure. Recherche le conteneur d'attribution de noms actuel d'un contrôle serveur avec l'id spécifié et un entier, spécifié dans le paramètre pathOffset, qui facilite la recherche. Vous ne devez pas substituer cette version de la méthode FindControl. (Hérité de Control.) | .gif) | Focus | Affecte le focus d'entrée à un contrôle. (Hérité de Control.) | .gif) | GetDesignModeState | Infrastructure. Obtient les données au moment du design pour un contrôle. (Hérité de Control.) | .gif) | GetHashCode | Sert de fonction de hachage pour un type particulier. (Hérité de Object.) | .gif) | GetRouteUrl(Object) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(RouteValueDictionary) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(String, Object) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire et à un nom d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(String, RouteValueDictionary) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire et à un nom d'itinéraire. (Hérité de Control.) | .gif) | GetType | Obtient le Type de l'instance actuelle. (Hérité de Object.) | .gif) | GetUniqueIDRelativeTo | Retourne la partie préfixée de la propriété UniqueID du contrôle spécifié. (Hérité de Control.) | .gif) | HasControls | Détermine si le contrôle serveur contient des contrôles enfants. (Hérité de Control.) | .gif) | HasEvents | Retourne une valeur indiquant si des événements sont inscrits pour le contrôle ou des contrôles enfants. (Hérité de Control.) | .gif) | IsLiteralContent | Infrastructure. Détermine si le contrôle serveur ne détient qu'un contenu littéral. (Hérité de Control.) | .gif) | LoadControlState | Restaure des informations sur l'état du contrôle à partir d'une demande de page antérieure enregistrée par la méthode SaveControlState. (Hérité de Control.) | .gif) | LoadViewState | Restaure les informations d'état d'affichage à partir d'une demande de page antérieure enregistrée par la méthode SaveViewState. (Hérité de Control.) | .gif) | MapPathSecure | Récupère le chemin d'accès physique auquel un chemin d'accès virtuel, absolu ou relatif, correspond. (Hérité de Control.) | .gif) | MemberwiseClone | Crée une copie superficielle de l'objet Object actif. (Hérité de Object.) | .gif) | OnBubbleEvent | Détermine s'il faut passer un événement en haut de la hiérarchie des contrôles serveur ASP.NET de la page. (Substitue ListViewItem..::.OnBubbleEvent(Object, EventArgs).) | .gif) | OnDataBinding | Déclenche l'événement DataBinding. (Hérité de Control.) | .gif) | OnInit | Déclenche l'événement Init. (Hérité de Control.) | .gif) | OnLoad | Déclenche l'événement Load. (Hérité de Control.) | .gif) | OnPreRender | Déclenche l'événement PreRender. (Hérité de Control.) | .gif) | OnUnload | Déclenche l'événement Unload. (Hérité de Control.) | .gif) | OpenFile | Obtient un Stream utilisé pour lire un fichier. (Hérité de Control.) | .gif) | RaiseBubbleEvent | Assigne les sources éventuelles de l'événement et ses informations au parent du contrôle. (Hérité de Control.) | .gif) | RemovedControl | Appelée après la suppression d'un contrôle enfant dans la collection Controls de l'objet Control. (Hérité de Control.) | .gif) | Render | Envoie le contenu du contrôle serveur à un objet HtmlTextWriter fourni, qui écrit le contenu à rendre sur le client. (Hérité de Control.) | .gif) | RenderChildren | Renvoie le contenu des enfants d'un contrôle serveur dans un objet HtmlTextWriter fourni, qui écrit le contenu à rendre sur le client. (Hérité de Control.) | .gif) | RenderControl(HtmlTextWriter) | Renvoie le contenu du contrôle serveur dans un objet HtmlTextWriter fourni et stocke des informations de traçage au sujet du contrôle si le traçage est activé. (Hérité de Control.) | .gif) | RenderControl(HtmlTextWriter, ControlAdapter) | Génère le contenu du contrôle serveur dans un objet HtmlTextWriter à l'aide d'un objet ControlAdapter fourni. (Hérité de Control.) | .gif) | ResolveAdapter | Obtient l'adaptateur de contrôles responsable du rendu du contrôle spécifié. (Hérité de Control.) | .gif) | ResolveClientUrl | Obtient une URL qui peut être utilisée par le navigateur. (Hérité de Control.) | .gif) | ResolveUrl | Convertit une URL en une URL que le client soit en mesure d'utiliser. (Hérité de Control.) | .gif) | SaveControlState | Enregistre les modifications éventuellement apportées à l'état du contrôle serveur depuis la publication de la page sur le serveur. (Hérité de Control.) | .gif) | SaveViewState | Enregistre les modifications éventuellement apportées à l'état d'affichage du contrôle serveur depuis la publication de la page sur le serveur. (Hérité de Control.) | .gif) | SetDesignModeState | Définit les données au moment du design pour un contrôle. (Hérité de Control.) | .gif) | SetRenderMethodDelegate | Infrastructure. Assigne un délégué de gestionnaires d'événements pour générer le rendu du contrôle serveur et de son contenu dans son contrôle parent. (Hérité de Control.) | .gif) | ToString | Retourne une chaîne qui représente l'objet actuel. (Hérité de Object.) | .gif) | TrackViewState | Provoque le suivi des modifications de l'état d'affichage pour le contrôle serveur afin qu'elles puissent être stockées dans l'objet StateBag du contrôle serveur. Cet objet est accessible via la propriété Control..::.ViewState. (Hérité de Control.) | Début

Méthodes d'extension

Implémentations d'interface explicite
|
| Nom | Description |
|---|
.gif) .gif) | IControlBuilderAccessor..::.ControlBuilder | Pour obtenir une description de ce membre, consultez IControlBuilderAccessor..::.ControlBuilder. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.GetDesignModeState | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.GetDesignModeState. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetDesignModeState | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.SetDesignModeState. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetOwnerControl | Infrastructure. Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.SetOwnerControl. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.UserData | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.UserData. (Hérité de Control.) | .gif) .gif) | IDataBindingsAccessor..::.DataBindings | Pour obtenir une description de ce membre, consultez IDataBindingsAccessor..::.DataBindings. (Hérité de Control.) | .gif) .gif) | IDataBindingsAccessor..::.HasDataBindings | Pour obtenir une description de ce membre, consultez IDataBindingsAccessor..::.HasDataBindings. (Hérité de Control.) | .gif) .gif) | IExpressionsAccessor..::.Expressions | Pour obtenir une description de ce membre, consultez IExpressionsAccessor..::.Expressions. (Hérité de Control.) | .gif) .gif) | IExpressionsAccessor..::.HasExpressions | Pour obtenir une description de ce membre, consultez IExpressionsAccessor..::.HasExpressions. (Hérité de Control.) | .gif) .gif) | IParserAccessor..::.AddParsedSubObject | Pour obtenir une description de ce membre, consultez IParserAccessor..::.AddParsedSubObject. (Hérité de Control.) | Début

Notes
La classe ListViewDataItem représente un élément de données individuel dans un contrôle ListView. Un élément de données correspond généralement à un enregistrement dans un objet source de données. La classe est dérivée de la classe ListViewItem. Chaque élément du contrôle ListView a un type d'élément désigné qui est représenté par la propriété ItemType. Lorsque le type d'élément est ListViewItemType..::.DataItem, vous pouvez utiliser la classe ListViewDataItem pour obtenir des informations supplémentaires sur l'élément. Le contrôle ListView stocke les éléments de données de la collection Items. Pour déterminer l'index d'un objet ListViewDataItem dans la collection Items, utilisez la propriété DisplayIndex. Pour déterminer l'index de l'élément de données dans la source de données sous-jacente, utilisez la propriété DataItemIndex. La différence entre ces propriétés d'index vient du fait que DisplayIndex représente la position de l'élément de données dans la page actuelle, alors que DataItemIndex est basé sur le décalage de la page. Si la fonctionnalité de pagination n'est pas activée dans le contrôle ListView à l'aide d'un contrôle DataPager, ces deux propriétés contiendront la même valeur. Vous pouvez accéder aux propriétés de l'objet de donnée sous-jacent en utilisant la propriété DataItem. La propriété DataItem est uniquement disponible pendant et après l'événement ItemDataBound d'un contrôle ListView. Pour obtenir la liste des valeurs initiales des propriétés d'une instance de la classe ListViewDataItem, consultez le constructeur ListViewDataItem.

Exemples
L'exemple suivant montre comment utiliser un objet ListViewDataItem pour récupérer une valeur de champ à partir d'un élément du contrôle ListView. Note de sécurité |
|---|
Cet exemple a une zone de texte qui accepte l'entrée d'utilisateur, ce qui constitue une menace éventuelle pour la sécurité. Par défaut, les pages Web ASP.NET vérifient que l'entrée d'utilisateur n'inclut pas de script ni d'éléments HTML. Pour plus d'informations, consultez Vue d'ensemble des attaques de script. |
<%@ Page Language="VB" %>
<%@ 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">
Protected Sub ContactsListView_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs)
'Verify there is an item being edited.
If ContactsListView.EditIndex >= 0 Then
'Get the item object.
Dim dataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
' Check for an item in edit mode.
If dataItem.DisplayIndex = ContactsListView.EditIndex Then
' Preselect the DropDownList control with the Title value
' for the current item.
' Retrieve the underlying data item. In this example
' the underlying data item is a DataRowView object.
Dim rowView As DataRowView = CType(dataItem.DataItem, DataRowView)
' Retrieve the Title value for the current item.
Dim title As String = rowView("Title").ToString()
' Retrieve the DropDownList control from the current row.
Dim list As DropDownList = CType(dataItem.FindControl("TitlesList"), DropDownList)
' Find the ListItem object in the DropDownList control with the
' title value and select the item.
Dim item As ListItem = list.Items.FindByText(title)
list.SelectedIndex = list.Items.IndexOf(item)
End If
End If
End Sub
Sub ContactsListView_ItemUpdating(ByVal sender As Object, ByVal e As ListViewUpdateEventArgs)
' Retrieve the row being edited.
Dim item As ListViewItem = ContactsListView.Items(ContactsListView.EditIndex)
' Retrieve the DropDownList control from the row.
Dim list As DropDownList = CType(item.FindControl("TitlesList"), DropDownList)
' Add the selected value of the DropDownList control to
' the NewValues collection. The NewValues collection is
' passed to the data source control, which then updates the
' data source.
e.NewValues("Title") = list.SelectedValue
End Sub 'ContactsListView_ItemUpdating
</script>
<html >
<head id="Head1" runat="server">
<title>ListView DataItem Example</title>
<link type="text/css" rel="stylesheet" href="StyleSheet.css" />
</head>
<body>
<form id="form1" runat="server">
<h3>ListViewDataItem Example</h3>
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
DataKeyNames="ContactID"
OnItemUpdating="ContactsListView_ItemUpdating"
OnItemDataBound="ContactsListView_ItemDataBound"
runat="server" >
<LayoutTemplate>
<table cellpadding="2" runat="server" id="tblContacts" width="640px">
<tr runat="server" id="itemPlaceholder" />
</table>
<asp:DataPager runat="server" ID="ContactsDataPager" PageSize="12">
<Fields>
<asp:NextPreviousPagerField
ShowFirstPageButton="true" ShowLastPageButton="true"
FirstPageText="|<< " LastPageText=" >>|"
NextPageText=" > " PreviousPageText=" < " />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<tr class="DataItem" runat="server">
<td>
<asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" />
</td>
<td>
<asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
</td>
<td>
<asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
</td>
<td>
<asp:Label ID="TitleLabel" runat="server" Text='<%#Eval("Title", "{0:d}") %>' />
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr class="EditItem">
<td>
<asp:LinkButton ID="UpdateButton" runat="server"
CommandName="Update" Text="Update" /><br />
<asp:LinkButton ID="CancelButton" runat="server"
CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label runat="server" ID="FirstNameLabel"
AssociatedControlID="FirstNameTextBox" Text="First Name:"/>
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%#Bind("FirstName") %>' MaxLength="50" />
</td>
<td>
<asp:Label runat="server" ID="LastNameLabel"
AssociatedControlID="LastNameTextBox" Text="Last Name:" />
<asp:TextBox ID="LastNameTextBox" runat="server"
Text='<%#Bind("LastName") %>' MaxLength="50" /><br />
</td>
<td>
<asp:Label runat="server" ID="TitleLabel"
AssociatedControlID="TitlesList" Text="Title:"/>
<asp:DropDownList ID="TitlesList"
DataSourceID="TitlesSqlDataSource"
DataTextField="Title"
runat="server">
</asp:DropDownList>
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="TitlesSqlDataSource"
SelectCommand="SELECT Distinct [Title] FROM Person.Contact ORDER BY [Title]"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
runat="server">
</asp:SqlDataSource>
<asp:SqlDataSource ID="ContactsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT [ContactID], [FirstName], [LastName], [Title] FROM Person.Contact"
UpdateCommand="UPDATE Person.Contact
SET FirstName = @FirstName, LastName = @LastName, Title = @Title
WHERE ContactID = @ContactID">
<UpdateParameters>
<asp:Parameter ConvertEmptyStringToNull="true" Name="Title" />
</UpdateParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
<%@ 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">
protected void ContactsListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
//Verify there is an item being edited.
if (ContactsListView.EditIndex >= 0)
{
//Get the item object.
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
// Check for an item in edit mode.
if (dataItem.DisplayIndex == ContactsListView.EditIndex)
{
// Preselect the DropDownList control with the Title value
// for the current item.
// Retrieve the underlying data item. In this example
// the underlying data item is a DataRowView object.
DataRowView rowView = (DataRowView)dataItem.DataItem;
// Retrieve the Title value for the current item.
String title = rowView["Title"].ToString();
// Retrieve the DropDownList control from the current row.
DropDownList list = (DropDownList)dataItem.FindControl("TitlesList");
// Find the ListItem object in the DropDownList control with the
// title value and select the item.
ListItem item = list.Items.FindByText(title);
list.SelectedIndex = list.Items.IndexOf(item);
}
}
}
void ContactsListView_ItemUpdating(Object sender, ListViewUpdateEventArgs e)
{
// Retrieve the row being edited.
ListViewItem item = ContactsListView.Items[ContactsListView.EditIndex];
// Retrieve the DropDownList control from the row.
DropDownList list = (DropDownList)item.FindControl("TitlesList");
// Add the selected value of the DropDownList control to
// the NewValues collection. The NewValues collection is
// passed to the data source control, which then updates the
// data source.
e.NewValues["Title"] = list.SelectedValue;
}
</script>
<html >
<head id="Head1" runat="server">
<title>ListView DataItem Example</title>
<link type="text/css" rel="stylesheet" href="StyleSheet.css" />
</head>
<body>
<form id="form1" runat="server">
<h3>ListViewDataItem Example</h3>
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
DataKeyNames="ContactID"
OnItemUpdating="ContactsListView_ItemUpdating"
OnItemDataBound="ContactsListView_ItemDataBound"
runat="server" >
<LayoutTemplate>
<table cellpadding="2" runat="server" id="tblContacts" width="640px">
<tr runat="server" id="itemPlaceholder" />
</table>
<asp:DataPager runat="server" ID="ContactsDataPager" PageSize="12">
<Fields>
<asp:NextPreviousPagerField
ShowFirstPageButton="true" ShowLastPageButton="true"
FirstPageText="|<< " LastPageText=" >>|"
NextPageText=" > " PreviousPageText=" < " />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<tr class="DataItem" runat="server">
<td>
<asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" />
</td>
<td>
<asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
</td>
<td>
<asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
</td>
<td>
<asp:Label ID="TitleLabel" runat="server" Text='<%#Eval("Title", "{0:d}") %>' />
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr class="EditItem">
<td>
<asp:LinkButton ID="UpdateButton" runat="server"
CommandName="Update" Text="Update" /><br />
<asp:LinkButton ID="CancelButton" runat="server"
CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label runat="server" ID="FirstNameLabel"
AssociatedControlID="FirstNameTextBox" Text="First Name:"/>
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%#Bind("FirstName") %>' MaxLength="50" />
</td>
<td>
<asp:Label runat="server" ID="LastNameLabel"
AssociatedControlID="LastNameTextBox" Text="Last Name:" />
<asp:TextBox ID="LastNameTextBox" runat="server"
Text='<%#Bind("LastName") %>' MaxLength="50" /><br />
</td>
<td>
<asp:Label runat="server" ID="TitleLabel"
AssociatedControlID="TitlesList" Text="Title:"/>
<asp:DropDownList ID="TitlesList"
DataSourceID="TitlesSqlDataSource"
DataTextField="Title"
runat="server">
</asp:DropDownList>
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="TitlesSqlDataSource"
SelectCommand="SELECT Distinct [Title] FROM Person.Contact ORDER BY [Title]"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
runat="server">
</asp:SqlDataSource>
<asp:SqlDataSource ID="ContactsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT [ContactID], [FirstName], [LastName], [Title] FROM Person.Contact"
UpdateCommand="UPDATE Person.Contact
SET FirstName = @FirstName, LastName = @LastName, Title = @Title
WHERE ContactID = @ContactID">
<UpdateParameters>
<asp:Parameter ConvertEmptyStringToNull="true" Name="Title" />
</UpdateParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
RéférenceAutres ressources
|