BoundField.HtmlEncode Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit une valeur indiquant si les valeurs de champ sont encodées au format HTML avant qu’elles ne soient affichées dans un BoundField objet.
public:
virtual property bool HtmlEncode { bool get(); void set(bool value); };
public virtual bool HtmlEncode { get; set; }
member this.HtmlEncode : bool with get, set
Public Overridable Property HtmlEncode As Boolean
Valeur de propriété
true si les valeurs de champ sont encodées au format HTML avant qu’elles ne soient affichées dans un BoundField objet ; sinon, false. La valeur par défaut est true.
Exemples
L’exemple de code suivant montre comment utiliser la HtmlEncode propriété pour empêcher que les valeurs de champ ne soient encodées au format HTML avant d’être affichées dans un BoundField objet.
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>BoundField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>BoundField Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
allowpaging="true"
runat="server">
<columns>
<asp:boundfield datafield="CustomerID"
readonly="true"
headertext="Customer ID"/>
<asp:boundfield datafield="CompanyName"
htmlencode="false"
headertext="Customer Name"/>
<asp:boundfield datafield="Address"
htmlencode="false"
headertext="Address"/>
<asp:boundfield datafield="City"
htmlencode="false"
headertext="City"/>
<asp:boundfield datafield="PostalCode"
htmlencode="false"
headertext="ZIP Code"/>
<asp:boundfield datafield="Country"
htmlencode="false"
headertext="Country"/>
</columns>
</asp:gridview>
<!-- 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="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>BoundField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>BoundField Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
allowpaging="true"
runat="server">
<columns>
<asp:boundfield datafield="CustomerID"
readonly="true"
headertext="Customer ID"/>
<asp:boundfield datafield="CompanyName"
htmlencode="false"
headertext="Customer Name"/>
<asp:boundfield datafield="Address"
htmlencode="false"
headertext="Address"/>
<asp:boundfield datafield="City"
htmlencode="false"
headertext="City"/>
<asp:boundfield datafield="PostalCode"
htmlencode="false"
headertext="ZIP Code"/>
<asp:boundfield datafield="Country"
htmlencode="false"
headertext="Country"/>
</columns>
</asp:gridview>
<!-- 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="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
Remarques
Utilisez la HtmlEncode propriété pour spécifier si les valeurs de champ sont encodées au format HTML dans leurs représentations sous forme de chaînes respectives avant qu’elles ne soient affichées dans un BoundField objet. Par exemple, si cette propriété est true, une valeur de chaîne de «< script> » est affichée en tant que «< script> ». Si cette propriété est false, la chaîne est rendue inchangée.
Note
Les valeurs de champ d’encodage HTML permettent d’empêcher l’affichage des attaques par script intersites et du contenu malveillant. Cette propriété doit être activée dans la mesure du possible.