BoundField.HtmlEncode Propiedad
En este artículo
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece un valor que indica si los valores de campo se codifican en HTML antes de mostrarlos en un objeto BoundField.
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
Es true
si los valores de campo se codifican en HTML antes de mostrarlos en un objeto BoundField; de lo contrario, es false
. De manera predeterminada, es true
.
En el ejemplo de código siguiente se muestra cómo usar la HtmlEncode propiedad para evitar que los valores de campo estén codificados en HTML antes de mostrarse en un BoundField objeto .
<%@ 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>
Utilice la HtmlEncode propiedad para especificar si los valores de campo están codificados en HTML en sus respectivas representaciones de cadena antes de que se muestren en un BoundField objeto . Por ejemplo, si esta propiedad es true
, un valor de cadena de "<script>" se representaría como "<script>". Si esta propiedad es false
, la cadena se representaría sin cambios.
Nota
Los valores de campo de codificación HTML ayudan a evitar que se muestren ataques de scripting entre sitios y contenido malintencionado. Esta propiedad debe habilitarse siempre que sea posible.
Producto | Versiones |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Comentarios de .NET
.NET es un proyecto de código abierto. Seleccione un vínculo para proporcionar comentarios: