DataControlField.Visible Proprietà
Definizione
Ottiene o imposta un valore che indica se viene eseguito il rendering di un campo di controllo dati.Gets or sets a value indicating whether a data control field is rendered.
public:
property bool Visible { bool get(); void set(bool value); };
public bool Visible { get; set; }
member this.Visible : bool with get, set
Public Property Visible As Boolean
Valore della proprietà
true
se DataControlField viene sottoposto a rendering; in caso contrario, false
.true
if the DataControlField is rendered; otherwise, false
. Il valore predefinito è true
.The default value is true
.
Esempio
Nell'esempio di codice seguente viene illustrato come BoundField utilizzare ButtonField gli oggetti e, derivati da DataControlField , per visualizzare le righe in un DetailsView controllo.The following code example demonstrates how to use BoundField and ButtonField objects, which are derived from DataControlField, to display rows in a DetailsView control. La Visible proprietà dell' BoundField oggetto che visualizza la EmployeeID
colonna è impostata su false
e la colonna non viene sottoposta a rendering dal DetailsView controllo.The Visible property of the BoundField object that displays the EmployeeID
column is set to false
, and the column is not rendered by the DetailsView control.
<%@ 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>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:detailsview
id="DetailsView1"
runat="server"
allowpaging="True"
datasourceid="SqlDataSource1"
autogeneraterows="False"
width="312px"
height="152px">
<fields>
<asp:boundfield
visible="False"
sortexpression="EmployeeID"
datafield="EmployeeID">
</asp:boundfield>
<asp:boundfield
sortexpression="LastName"
datafield="LastName"
headertext="LastName">
</asp:boundfield>
<asp:boundfield
sortexpression="FirstName"
datafield="FirstName"
headertext="FirstName">
</asp:boundfield>
<asp:boundfield
sortexpression="Title"
datafield="Title"
headertext="Title">
</asp:boundfield>
<asp:buttonfield text="Button">
<controlstyle font-bold="True" forecolor="Red" />
</asp:buttonfield>
</fields>
</asp:detailsview>
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
selectcommand="SELECT * FROM Employees"
connectionstring="<%$ ConnectionStrings:MyNorthwind%>">
</asp:sqldatasource>
</form>
</body>
</html>
<%@ page language="VB" %>
<!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>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:detailsview
id="DetailsView1"
runat="server"
allowpaging="True"
datasourceid="SqlDataSource1"
autogeneraterows="False"
width="312px"
height="152px">
<fields>
<asp:boundfield
visible="False"
sortexpression="EmployeeID"
datafield="EmployeeID">
</asp:boundfield>
<asp:boundfield
sortexpression="LastName"
datafield="LastName"
headertext="LastName">
</asp:boundfield>
<asp:boundfield
sortexpression="FirstName"
datafield="FirstName"
headertext="FirstName">
</asp:boundfield>
<asp:boundfield
sortexpression="Title"
datafield="Title"
headertext="Title">
</asp:boundfield>
<asp:buttonfield text="Button">
<controlstyle font-bold="True" forecolor="Red" />
</asp:buttonfield>
</fields>
</asp:detailsview>
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
selectcommand="SELECT * FROM Employees"
connectionstring="<%$ ConnectionStrings:MyNorthwind%>">
</asp:sqldatasource>
</form>
</body>
</html>
Commenti
Utilizzare la Visible proprietà per mostrare o nascondere DataControlField gli oggetti in un controllo con associazione a dati.Use the Visible property to show or hide DataControlField objects in a data-bound control.
Se la Visible proprietà è false
, i valori dei dati non verranno visualizzati e non verrà eseguita una sequenza di andata e ritorno al client.If the Visible property is false
, the data values are not displayed and do not make a round-trip to the client. Se si desidera eseguire il round trip dei dati per un campo non visibile, aggiungere il nome del campo alla DataKeyNames
proprietà del controllo associato a dati.If you want to round-trip the data for a field that is not visible, add the field name to the DataKeyNames
property of the data-bound control.