共用方式為


DataControlField.Visible 屬性

定義

取得或設定值,指示是否呈現資料控制項欄位。

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

屬性值

Boolean

如果呈現 DataControlField,則為 true,否則為 false。 預設值是 true

範例

下列程式碼範例示範如何使用 BoundField 衍生自 DataControlField 的 和 ButtonField 物件,在 控制項中 DetailsView 顯示資料列。 Visible顯示 EmployeeID 資料行之 BoundField 物件的 屬性會設定為 false ,而且控制項不會轉 DetailsView 譯資料行。

<%@ 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>

備註

Visible使用 屬性來顯示或隱藏 DataControlField 資料繫結控制項中的物件。

Visible如果 屬性為 false ,則不會顯示資料值,而且不會對用戶端進行往返。 如果您想要往返不可見之欄位的資料,請將功能變數名稱新增至 DataKeyNames 資料繫結控制項的 屬性。

適用於