DropDownList 類別

定義

代表允許使用者從下拉式清單選取單一項目的控制項。

public ref class DropDownList : System::Web::UI::WebControls::ListControl, System::Web::UI::IPostBackDataHandler
[System.Web.UI.ValidationProperty("SelectedItem")]
public class DropDownList : System.Web.UI.WebControls.ListControl, System.Web.UI.IPostBackDataHandler
[<System.Web.UI.ValidationProperty("SelectedItem")>]
type DropDownList = class
    inherit ListControl
    interface IPostBackDataHandler
Public Class DropDownList
Inherits ListControl
Implements IPostBackDataHandler
繼承
繼承
屬性
實作

範例

具有原始程式碼的 Visual Studio 網站專案隨附于本主題: 下載

下列程式碼範例示範如何建立包含四個專案 DropDownList 的控制項。

<%@ Page Language="C#" AutoEventWireup="True" %>

<!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" >
   <script runat="server" >
  
      void Selection_Change(Object sender, EventArgs e)
      {

         // Set the background color for days in the Calendar control
         // based on the value selected by the user from the 
         // DropDownList control.
         Calendar1.DayStyle.BackColor = 
             System.Drawing.Color.FromName(ColorList.SelectedItem.Value);

      }
  
   </script>
  
<head runat="server">
    <title> DropDownList Example </title>
</head>
<body>

   <form id="form1" runat="server">
  
      <h3> DropDownList Example </h3>

      Select a background color for days in the calendar.

      <br /><br /> 
  
      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>

      <br /><br />

      <table cellpadding="5">

         <tr>

            <td>

               Background color:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">

                  <asp:ListItem Selected="True" Value="White"> White </asp:ListItem>
                  <asp:ListItem Value="Silver"> Silver </asp:ListItem>
                  <asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
                  <asp:ListItem Value="Khaki"> Khaki </asp:ListItem>
                  <asp:ListItem Value="DarkKhaki"> Dark Khaki </asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>
  
      </table>
  
   </form>

</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!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" >
   <script runat="server" >
  
      Sub Selection_Change(sender As Object, e As EventArgs)

         ' Set the background color for days in the Calendar control
         ' based on the value selected by the user from the
         '  DropDownList control.
         Calendar1.DayStyle.BackColor = _
             System.Drawing.Color.FromName(ColorList.SelectedItem.Value)

      End Sub
  
   </script>
  
<head runat="server">
    <title> DropDownList Example </title>
</head>
<body>

   <form id="form1" runat="server">
  
      <h3> DropDownList Example </h3>

      Select a background color for days in the calendar.

      <br /><br /> 
  
      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>

      <br /><br />

      <table cellpadding="5">

         <tr>

            <td>

               Background color:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">

                  <asp:ListItem Selected="True" Value="White"> White </asp:ListItem>
                  <asp:ListItem Value="Silver"> Silver </asp:ListItem>
                  <asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
                  <asp:ListItem Value="Khaki"> Khaki </asp:ListItem>
                  <asp:ListItem Value="DarkKhaki"> Dark Khaki </asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>
         
      </table>   
  
   </form>

</body>
</html>

下列程式碼範例示範如何透過資料系結建立 DropDownList 控制項。

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<!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" >
   <script runat="server" >
  
      void Selection_Change(Object sender, EventArgs e)
      {

         // Set the background color for days in the Calendar control
         // based on the value selected by the user from the 
         // DropDownList control.
         Calendar1.DayStyle.BackColor = 
             System.Drawing.Color.FromName(ColorList.SelectedItem.Value);

      }

      void Page_Load(Object sender, EventArgs e)
      {
  
         // Load data for the DropDownList control only once, when the 
         // page is first loaded.
         if(!IsPostBack)
         {

            // Specify the data source and field names for the Text 
            // and Value properties of the items (ListItem objects) 
            // in the DropDownList control.
            ColorList.DataSource = CreateDataSource();
            ColorList.DataTextField = "ColorTextField";
            ColorList.DataValueField = "ColorValueField";

            // Bind the data to the control.
            ColorList.DataBind();

            // Set the default selected item, if desired.
            ColorList.SelectedIndex = 0;

         }

      }

      ICollection CreateDataSource() 
      {
      
         // Create a table to store data for the DropDownList control.
         DataTable dt = new DataTable();
         
         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("ColorTextField", typeof(String)));
         dt.Columns.Add(new DataColumn("ColorValueField", typeof(String)));
 
         // Populate the table with sample values.
         dt.Rows.Add(CreateRow("White", "White", dt));
         dt.Rows.Add(CreateRow("Silver", "Silver", dt));
         dt.Rows.Add(CreateRow("Dark Gray", "DarkGray", dt));
         dt.Rows.Add(CreateRow("Khaki", "Khaki", dt));
         dt.Rows.Add(CreateRow("Dark Khaki", "DarkKhaki", dt));
 
         // Create a DataView from the DataTable to act as the data source
         // for the DropDownList control.
         DataView dv = new DataView(dt);
         return dv;

      }

      DataRow CreateRow(String Text, String Value, DataTable dt)
      {

         // Create a DataRow using the DataTable defined in the 
         // CreateDataSource method.
         DataRow dr = dt.NewRow();
 
         // This DataRow contains the ColorTextField and ColorValueField 
         // fields, as defined in the CreateDataSource method. Set the 
         // fields with the appropriate value. Remember that column 0 
         // is defined as ColorTextField, and column 1 is defined as 
         // ColorValueField.
         dr[0] = Text;
         dr[1] = Value;
 
         return dr;

      }
  
   </script>
  
<head runat="server">
    <title> DropDownList Data Binding Example </title>
</head>
<body>

   <form id="form1" runat="server">
  
      <h3> DropDownList Data Binding Example </h3>

      Select a background color for days in the calendar.

      <br /><br /> 
  
      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>

      <br /><br />

      <table cellpadding="5">

         <tr>

            <td>

               Background color:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server"/>

            </td>

         </tr>
         
      </table>   
  
   </form>

</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<!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" >
   <script runat="server" >
  
      Sub Selection_Change(sender as Object, e As EventArgs)

         ' Set the background color for days in the Calendar control 
         ' based on the value selected by the user from the
         ' DropDownList control.
         Calendar1.DayStyle.BackColor = _
             System.Drawing.Color.FromName(ColorList.SelectedItem.Value)

      End Sub

      Sub Page_Load(sender as Object, e As EventArgs)
  
         ' Load data for the DropDownList control only once, when the 
         ' page is first loaded.
         If Not IsPostBack Then

            ' Specify the data source and field names for the Text 
            ' and Value properties of the items (ListItem objects)
            ' in the DropDownList control.
            ColorList.DataSource = CreateDataSource()
            ColorList.DataTextField = "ColorTextField"
            ColorList.DataValueField = "ColorValueField"

            ' Bind the data to the control.
            ColorList.DataBind()

            ' Set the default selected item, if desired.
            ColorList.SelectedIndex = 0

         End If

      End Sub

      Function CreateDataSource() As ICollection 
      
         ' Create a table to store data for the DropDownList control.
         Dim dt As DataTable = New DataTable()
         
         ' Define the columns of the table.
         dt.Columns.Add(new DataColumn("ColorTextField", GetType(String)))
         dt.Columns.Add(new DataColumn("ColorValueField", GetType(String)))
 
         ' Populate the table with sample values.
         dt.Rows.Add(CreateRow("White", "White", dt))
         dt.Rows.Add(CreateRow("Silver", "Silver", dt))
         dt.Rows.Add(CreateRow("Dark Gray", "DarkGray", dt))
         dt.Rows.Add(CreateRow("Khaki", "Khaki", dt))
         dt.Rows.Add(CreateRow("Dark Khaki", "DarkKhaki", dt))
 
         ' Create a DataView from the DataTable to act as the data source
         ' for the DropDownList control.
         Dim dv As DataView = New DataView(dt)
         Return dv

      End Function

      Function CreateRow(Text As String, Value As String, dt As DataTable) As DataRow 

         ' Create a DataRow using the DataTable defined in the 
         ' CreateDataSource method.
         Dim dr As DataRow = dt.NewRow()
 
         ' This DataRow contains the ColorTextField and ColorValueField 
         ' fields, as defined in the CreateDataSource method. Set the 
         ' fields with the appropriate value. Remember that column 0 
         ' is defined as ColorTextField, and column 1 is defined as 
         ' ColorValueField.
         dr(0) = Text
         dr(1) = Value
 
         Return dr

      End Function
  
   </script>
  
<head runat="server">
    <title> DropDownList Data Binding Example </title>
</head>
<body>

   <form id="form1" runat="server">
  
      <h3> DropDownList Data Binding Example </h3>

      Select a background color for days in the calendar.

      <br /><br /> 
  
      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>

      <br /><br />

      <table cellpadding="5">

         <tr>

            <td>

               Background color:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server"/>

            </td>

         </tr>
         
      </table>   
  
   </form>

</body>
</html>

備註

本主題內容:

簡介

DropDownList使用 控制項來建立單一選取清單控制項。 您可以藉由設定 BorderColorBorderStyleBorderWidth 屬性來控制控制項的外觀 DropDownList

若要指定您想要出現在 控制項中的 DropDownList 專案,請在控制項的開頭和結束記號 DropDownList 之間放置 ListItem 每個專案的 物件。

控制項 DropDownList 也支援資料系結。 若要將控制項系結至資料來源,請建立資料來源,例如 System.Collections.ArrayList 物件,其中包含要顯示在 控制項中的專案。 然後,使用 Control.DataBind 方法將資料來源系結至 DropDownList 控制項。

SelectedIndex使用 屬性,以程式設計方式判斷使用者從 DropDownList 控制項選取的專案索引。 然後,索引可用來從 Items 控制項的集合擷取選取的專案。

Accessibility

如需如何設定此控制項以產生符合協助工具標準的標記的相關資訊,請參閱 Visual Studio 中的協助工具,以及 ASP.NETASP.NET 控制項和協助工具

宣告式語法

<asp:DropDownList  
    AccessKey="string"  
    AppendDataBoundItems="True|False"  
    AutoPostBack="True|False"  
    BackColor="color name|#dddddd"  
    BorderColor="color name|#dddddd"  
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|  
        Inset|Outset"  
    BorderWidth="size"  
    CausesValidation="True|False"  
    CssClass="string"  
    DataMember="string"  
    DataSource="string"  
    DataSourceID="string"  
    DataTextField="string"  
    DataTextFormatString="string"  
    DataValueField="string"  
    Enabled="True|False"  
    EnableTheming="True|False"  
    EnableViewState="True|False"  
    Font-Bold="True|False"  
    Font-Italic="True|False"  
    Font-Names="string"  
    Font-Overline="True|False"  
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|  
        Large|X-Large|XX-Large"  
    Font-Strikeout="True|False"  
    Font-Underline="True|False"  
    ForeColor="color name|#dddddd"  
    Height="size"  
    ID="string"  
    OnDataBinding="DataBinding event handler"  
    OnDataBound="DataBound event handler"  
    OnDisposed="Disposed event handler"  
    OnInit="Init event handler"  
    OnLoad="Load event handler"  
    OnPreRender="PreRender event handler"  
    OnSelectedIndexChanged="SelectedIndexChanged event handler"  
    OnTextChanged="TextChanged event handler"  
    OnUnload="Unload event handler"  
    runat="server"  
    SelectedIndex="integer"  
    SelectedValue="string"  
    SkinID="string"  
    Style="string"  
    TabIndex="integer"  
    ToolTip="string"  
    ValidationGroup="string"  
    Visible="True|False"  
    Width="size"  
>  
            <asp:ListItem  
                Enabled="True|False"  
                Selected="True|False"  
                Text="string"  
                Value="string"  
            />  
</asp:DropDownList>  

建構函式

DropDownList()

初始化 DropDownList 類別的新執行個體。

屬性

AccessKey

取得或設定便捷鍵 (Access Key),可讓您快速巡覽至 Web 伺服器控制項。

(繼承來源 WebControl)
Adapter

針對控制項取得瀏覽器的特定配置器。

(繼承來源 Control)
AppendDataBoundItems

取得或設定值,表示是否在資料繫結之前清除清單項目。

(繼承來源 ListControl)
AppRelativeTemplateSourceDirectory

取得或設定包含了此控制項之 PageUserControl 物件的相對應用程式虛擬目錄。

(繼承來源 Control)
Attributes

取得任意屬性 (Attribute) 的集合 (只供呈現),不與控制項上的屬性 (Property) 對應。

(繼承來源 WebControl)
AutoPostBack

取得或設定值,表示當使用者變更清單選取項目時,是否會自動向伺服器回傳。

(繼承來源 ListControl)
BackColor

取得或設定 Web 伺服器控制項的背景色彩。

(繼承來源 WebControl)
BindingContainer

取得包含了此控制項之資料繫結的控制項。

(繼承來源 Control)
BorderColor

取得或設定控制項的框線色彩。

BorderStyle

取得或設定控制項的框線樣式。

BorderWidth

取得或設定控制項的框線寬度。

CausesValidation

取得或設定值,表示是否要在按一下衍生自 ListControl 類別的控制項時執行驗證。

(繼承來源 ListControl)
ChildControlsCreated

取得值,指出是否已經建立伺服器控制項的子控制項。

(繼承來源 Control)
ClientID

取得 ASP.NET 所產生之 HTML 標記的控制項識別碼。

(繼承來源 Control)
ClientIDMode

取得或設定用來產生 ClientID 屬性值的演算法。

(繼承來源 Control)
ClientIDSeparator

取得字元值,表示在 ClientID 屬性中所使用的分隔字元。

(繼承來源 Control)
Context

取得與目前 Web 要求的伺服器控制項關聯的 HttpContext 物件。

(繼承來源 Control)
Controls

取得 ControlCollection 物件,表示 UI 階層架構中指定之伺服器控制項的子控制項。

(繼承來源 Control)
ControlStyle

取得 Web 伺服器控制項的樣式。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
ControlStyleCreated

取得值,指出 Style 物件是否已經為 ControlStyle 屬性建立。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
CssClass

取得或設定用戶端上 Web 伺服器控制項所呈現的階層式樣式表 (CSS)。

(繼承來源 WebControl)
DataItemContainer

如果命名容器實作 IDataItemContainer,則取得命名容器的參考。

(繼承來源 Control)
DataKeysContainer

如果命名容器實作 IDataKeysControl,則取得命名容器的參考。

(繼承來源 Control)
DataMember

取得或設定 DataSource 中要繫結至控制項的特定表格。

(繼承來源 ListControl)
DataSource

取得或設定可填入清單控制項項目的資料來源。

(繼承來源 ListControl)
DataSourceID

取得或設定控制項的識別碼,資料繫結控制項會由此擷取其項目清單。

(繼承來源 DataBoundControl)
DataSourceObject

取得物件,這個物件會實作可提供物件資料內容之存取權的 IDataSource 介面。

(繼承來源 DataBoundControl)
DataTextField

取得或設定提供清單項目文字內容的資料來源欄位。

(繼承來源 ListControl)
DataTextFormatString

取得或設定格式化字串,這個字串可用來控制繫結至清單控制項之資料的顯示方式。

(繼承來源 ListControl)
DataValueField

取得或設定提供每個清單項目值的資料來源欄位。

(繼承來源 ListControl)
DesignMode

取得值,指出控制項是否正用於設計介面上。

(繼承來源 Control)
Enabled

取得或設定值,指出 Web 伺服器控制項是否啟用。

(繼承來源 WebControl)
EnableTheming

取得或設定值,指出佈景主題是否套用至此控制項。

(繼承來源 WebControl)
EnableViewState

取得或設定值,該值表示伺服器控制項是否對要求的用戶端而言保持其檢視狀態,以及它包含的任何子控制項狀態。

(繼承來源 Control)
Events

取得控制項事件處理常式委派 (Delegate) 的清單。 這個屬性是唯讀的。

(繼承來源 Control)
Font

取得與 Web 伺服器控制項關聯的字型屬性。

(繼承來源 WebControl)
ForeColor

取得或設定 Web 伺服器控制項的前景色彩 (通常是文字的色彩)。

(繼承來源 WebControl)
HasAttributes

取得值,指出控制項是否已經設定屬性。

(繼承來源 WebControl)
HasChildViewState

取得值,指出目前伺服器控制項的子控制項是否有任何已儲存的檢視狀態設定。

(繼承來源 Control)
Height

取得或設定 Web 伺服器控制項的高度。

(繼承來源 WebControl)
ID

取得或設定指派給伺服器控制項的程式設計識別項。

(繼承來源 Control)
IdSeparator

取得用來分隔控制項識別項的字元。

(繼承來源 Control)
Initialized

取得值,指出是否已初始化資料繫結控制項。

(繼承來源 BaseDataBoundControl)
IsBoundUsingDataSourceID

取得值,指出是否已設定 DataSourceID 屬性。

(繼承來源 BaseDataBoundControl)
IsChildControlStateCleared

取得值,指出這個控制項中所包含的控制項是否有控制項狀態。

(繼承來源 Control)
IsDataBindingAutomatic

取得值,指出資料繫結是否為自動。

(繼承來源 BaseDataBoundControl)
IsEnabled

取得值,指出是否啟用控制項。

(繼承來源 WebControl)
IsTrackingViewState

取得值,指出伺服器控制項是否正在儲存檢視狀態的變更。

(繼承來源 Control)
IsUsingModelBinders

取得值,指出模型繫結是否正在使用。

(繼承來源 DataBoundControl)
IsViewStateEnabled

取得值,指出這個控制項是否已啟用檢視狀態。

(繼承來源 Control)
Items

取得清單控制項中的項目集合。

(繼承來源 ListControl)
ItemType

取得或設定強型別資料繫結的資料項目型別名稱。

(繼承來源 DataBoundControl)
LoadViewStateByID

取得值,指出控制項是否依 ID (而不是索引) 參與載入其檢視狀態。

(繼承來源 Control)
NamingContainer

取得伺服器控制項命名容器的參考,其建立唯一命名空間,在具有相同 ID 屬性值的伺服器控制項之間作區別。

(繼承來源 Control)
Page

取得含有伺服器控制項的 Page 執行個體的參考。

(繼承來源 Control)
Parent

在網頁控制階層架構中取得伺服器控制項之父控制項的參考。

(繼承來源 Control)
RenderingCompatibility

取得值,這個值會指定將與呈現 HTML 相容的 ASP.NET 版本。

(繼承來源 Control)
RequiresDataBinding

取得或設定值,指出是否應該呼叫 DataBind() 方法。

(繼承來源 BaseDataBoundControl)
SelectArguments

取得 DataSourceSelectArguments 物件,當從資料來源控制項擷取資料時資料繫結控制項會使用它。

(繼承來源 DataBoundControl)
SelectedIndex

取得或設定 DropDownList 控制項中選取之項目的索引。

SelectedItem

取得清單控制項中具有最低索引的選取項目。

(繼承來源 ListControl)
SelectedValue

取得清單控制項中選取項目的值,或選取清單控制項中包含指定值的項目。

(繼承來源 ListControl)
SelectMethod

為了讀取資料要呼叫的方法的名稱。

(繼承來源 DataBoundControl)
Site

當呈現在設計介面上時,取得裝載目前控制項之容器的資訊。

(繼承來源 Control)
SkinID

取得或設定要套用至控制項的面板。

(繼承來源 WebControl)
Style

取得文字屬性的集合,將呈現為 Web 伺服器控制項的外部標記上的樣式屬性。

(繼承來源 WebControl)
SupportsDisabledAttribute

取得值,這個值表示當控制項的 disabled 屬性為 IsEnabled 時,控制項是否應該將呈現之 HTML 項目的 false 屬性設為 "disabled"。

SupportsDisabledAttribute

取得值,這個值表示當控制項的 disabled 屬性為 IsEnabled 時,控制項是否應該將呈現之 HTML 項目的 false 屬性設為 "disabled"。

(繼承來源 WebControl)
SupportsDisabledAttribute

取得值,這個值表示當控制項的 disabled 屬性為 IsEnabled 時,控制項是否應該將呈現之 HTML 項目的 false 屬性設為 "disabled"。

(繼承來源 BaseDataBoundControl)
TabIndex

取得或設定 Web 伺服器控制項的定位索引。

(繼承來源 WebControl)
TagKey

取得 ListControl 控制項的 HtmlTextWriterTag 值。

(繼承來源 ListControl)
TagName

取得控制項標記的名稱。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
TemplateControl

取得或設定包含了此控制項之樣板的參考。

(繼承來源 Control)
TemplateSourceDirectory

取得包含目前伺服器控制項的 PageUserControl 的虛擬目錄。

(繼承來源 Control)
Text

取得或設定 ListControl 控制項的 SelectedValue 屬性。

(繼承來源 ListControl)
ToolTip

取得或設定當滑鼠指標停留在控制項上方時顯示的工具提示文字。

ToolTip

取得或設定當滑鼠指標停留在 Web 伺服器控制項時顯示的文字。

(繼承來源 WebControl)
UniqueID

取得伺服器控制項唯一的、符合階層架構的識別項。

(繼承來源 Control)
ValidateRequestMode

取得或設定值,指出控制項是否對來自瀏覽器的用戶端輸入檢查潛在的危險值。

(繼承來源 Control)
ValidationGroup

取得或設定控制項群組,衍生自 ListControl 類別的控制項會在回傳至伺服器時,針對這個群組進行驗證。

(繼承來源 ListControl)
ViewState

取得狀態資訊的字典,允許您在相同網頁的多個要求之間,儲存和還原伺服器控制項的檢視狀態。

(繼承來源 Control)
ViewStateIgnoresCase

取得值,指出 StateBag 物件是否不區分大小寫。

(繼承來源 Control)
ViewStateMode

取得或設定這個控制項的檢視狀態模式。

(繼承來源 Control)
Visible

取得或設定值,指出伺服器控制項是否會轉譯為頁面上的 UI。

(繼承來源 Control)
Width

取得或設定 Web 伺服器控制項的寬度。

(繼承來源 WebControl)

方法

AddAttributesToRender(HtmlTextWriter)

將需要呈現的 HTML 屬性和樣式加入指定的 HtmlTextWriter 物件中。

AddedControl(Control, Int32)

在子控制項加入 Control 物件的 Controls 集合後呼叫。

(繼承來源 Control)
AddParsedSubObject(Object)

通知伺服器控制項,XML 或 HTML 項目已剖析,並將項目加入伺服器控制項的 ControlCollection 物件中。

(繼承來源 Control)
ApplyStyle(Style)

將指定樣式的任何非空白項目加入到 Web 控制項中,覆寫控制項的任何現有的樣式項目。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
ApplyStyleSheetSkin(Page)

將頁面樣式表中所定義的樣式屬性套用至控制項。

(繼承來源 Control)
BeginRenderTracing(TextWriter, Object)

開始進行轉譯資料的設計階段追蹤。

(繼承來源 Control)
BuildProfileTree(String, Boolean)

收集伺服器控制項的相關資訊,並在頁面啟用追蹤時將此資訊傳遞至 Trace 屬性以顯示之。

(繼承來源 Control)
ClearCachedClientID()

將快取的 ClientID 值設定為 null

(繼承來源 Control)
ClearChildControlState()

刪除伺服器控制項之子控制項的控制項狀態資訊。

(繼承來源 Control)
ClearChildState()

刪除所有伺服器控制項之子控制項的檢視狀態和控制項狀態資訊。

(繼承來源 Control)
ClearChildViewState()

刪除所有伺服器控制項之子控制項的檢視狀態資訊。

(繼承來源 Control)
ClearEffectiveClientIDMode()

將目前的控制項執行個體和任何子控制項的 ClientIDMode 屬性設定為 Inherit

(繼承來源 Control)
ClearSelection()

清除清單選取項目,並將所有項目的 Selected 屬性設為 false。

(繼承來源 ListControl)
ConfirmInitState()

設定資料繫結控制項之初始化的狀態。

(繼承來源 BaseDataBoundControl)
CopyBaseAttributes(WebControl)

將不被 Style 物件封裝的屬性從指定的 Web 伺服器控制項複製到呼叫這個方法的 Web 伺服器控制項上。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
CreateChildControls()

由 ASP.NET 網頁架構呼叫,通知使用組合實作的伺服器控制項來建立所包含的任何子控制項,以準備回傳或呈現。

(繼承來源 Control)
CreateControlCollection()

建立儲存子控制項的集合。

CreateControlStyle()

建立樣式物件,這個物件被 WebControl 類別內部使用,以實作所有的樣式相關屬性。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
CreateDataSourceSelectArguments()

如果沒有指定引數,則會建立資料繫結控制項使用的預設 DataSourceSelectArguments 物件。

(繼承來源 DataBoundControl)
DataBind()

將資料來源繫結至所叫用的伺服器控制項及其所有子控制項。

(繼承來源 Control)
DataBind()

將資料來源繫結至所叫用的伺服器控制項及其所有子控制項。

(繼承來源 BaseDataBoundControl)
DataBind(Boolean)

使用會引發 DataBinding 事件的選項,繫結資料來源至叫用的伺服器控制項及其所有子控制項。

(繼承來源 Control)
DataBindChildren()

繫結資料來源至伺服器控制項的子控制項。

(繼承來源 Control)
Dispose()

啟用伺服器控制項,在它從記憶體釋放之前執行最後清除。

(繼承來源 Control)
EndRenderTracing(TextWriter, Object)

結束轉譯資料的設計階段追蹤。

(繼承來源 Control)
EnsureChildControls()

判斷伺服器控制項是否包含子控制項。 如果不包含,則建立子控制項。

(繼承來源 Control)
EnsureDataBound()

如果設定了 DataBind() 屬性且資料繫結控制項標記為需要繫結,則會呼叫 DataSourceID 方法。

(繼承來源 BaseDataBoundControl)
EnsureID()

為尚未指定識別項的控制項,建立識別項。

(繼承來源 Control)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
FindControl(String)

在目前命名容器搜尋具有指定 id 參數的伺服器控制項。

(繼承來源 Control)
FindControl(String, Int32)

使用指定的 id 和有助於搜尋之 pathOffset 參數中所指定的整數,在目前的命名容器中搜尋伺服器控制項。 您不應該覆寫這個版本的 FindControl 方法。

(繼承來源 Control)
Focus()

設定控制項的輸入焦點。

(繼承來源 Control)
GetData()

擷取 DataSourceView 物件,資料繫結控制項會用來執行資料作業。

(繼承來源 DataBoundControl)
GetDataSource()

擷取與資料繫結控制項關聯的 IDataSource 介面 (如果有的話)。

(繼承來源 DataBoundControl)
GetDesignModeState()

取得控制項的設計階段資料。

(繼承來源 Control)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetRouteUrl(Object)

取得會對應於一組路由參數的 URL。

(繼承來源 Control)
GetRouteUrl(RouteValueDictionary)

取得會對應於一組路由參數的 URL。

(繼承來源 Control)
GetRouteUrl(String, Object)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。

(繼承來源 Control)
GetRouteUrl(String, RouteValueDictionary)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。

(繼承來源 Control)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetUniqueIDRelativeTo(Control)

傳回指定之控制項 UniqueID 屬性的前置部分。

(繼承來源 Control)
HasControls()

判斷伺服器控制項是否包含任何子控制項。

(繼承來源 Control)
HasEvents()

傳回值,指出控制項或任何子控制項的事件是否已註冊。

(繼承來源 Control)
IsLiteralContent()

判斷伺服器控制項是否只儲存常值內容。

(繼承來源 Control)
LoadControlState(Object)

SaveControlState() 方法所儲存的上一頁要求中,還原控制項狀態資訊。

(繼承來源 Control)
LoadPostData(String, NameValueCollection)

處理 DropDownList 控制項的回傳資料。

LoadViewState(Object)

載入先前儲存的 DetailsView 控制項檢視狀態。

(繼承來源 ListControl)
MapPathSecure(String)

擷取虛擬絕對路徑或相對路徑所對應至的實體路徑。

(繼承來源 Control)
MarkAsDataBound()

將檢視狀態中的控制項狀態設為已成功繫結至資料。

(繼承來源 DataBoundControl)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MergeStyle(Style)

將指定樣式的任何非空白項目複製到 Web 控制項,但不覆寫控制項的任何現有樣式項目。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
OnBubbleEvent(Object, EventArgs)

決定伺服器控制項的事件是否要在頁面的 UI 伺服器控制項階層架構中向上傳遞。

(繼承來源 Control)
OnCreatingModelDataSource(CreatingModelDataSourceEventArgs)

引發 CreatingModelDataSource 事件。

(繼承來源 DataBoundControl)
OnDataBinding(EventArgs)

引發 DataBinding 事件。

(繼承來源 ListControl)
OnDataBound(EventArgs)

引發 DataBound 事件。

(繼承來源 BaseDataBoundControl)
OnDataPropertyChanged()

其中一個基底資料來源識別屬性變更之後,將資料繫結控制項重新繫結至其資料。

(繼承來源 DataBoundControl)
OnDataSourceViewChanged(Object, EventArgs)

引發 DataSourceViewChanged 事件。

(繼承來源 DataBoundControl)
OnInit(EventArgs)

引發 Init 事件。

(繼承來源 Control)
OnInit(EventArgs)

處理 Init 事件。

(繼承來源 BaseDataBoundControl)
OnLoad(EventArgs)

引發 Load 事件。

(繼承來源 Control)
OnLoad(EventArgs)

處理 Load 事件。

(繼承來源 DataBoundControl)
OnPagePreLoad(Object, EventArgs)

設定資料繫結控制項在載入控制項之前的初始化狀態。

(繼承來源 DataBoundControl)
OnPreRender(EventArgs)

引發 PreRender 事件。

(繼承來源 ListControl)
OnSelectedIndexChanged(EventArgs)

引發 SelectedIndexChanged 事件。 這個方法可讓您提供該事件的自訂處理常式。

(繼承來源 ListControl)
OnTextChanged(EventArgs)

引發 TextChanged 事件。

(繼承來源 ListControl)
OnUnload(EventArgs)

引發 Unload 事件。

(繼承來源 Control)
OpenFile(String)

取得用來讀取檔案的 Stream

(繼承來源 Control)
PerformDataBinding(IEnumerable)

將指定的資料來源繫結至衍生自 ListControl 類別的控制項。

(繼承來源 ListControl)
PerformSelect()

從關聯的資料來源擷取資料。

(繼承來源 ListControl)
RaiseBubbleEvent(Object, EventArgs)

指派事件的任何來源和它的資訊至控制項的父控制項。

(繼承來源 Control)
RaisePostDataChangedEvent()

在回傳發生時引發 DropDownList 控制項的事件。

RemovedControl(Control)

Control 物件的 Controls 集合中移除子控制項之後呼叫。

(繼承來源 Control)
Render(HtmlTextWriter)

將控制項呈現在指定的 HTML 寫入器中。

(繼承來源 WebControl)
RenderBeginTag(HtmlTextWriter)

將控制項的 HTML 開頭標記呈現在指定的寫入器中。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
RenderChildren(HtmlTextWriter)

將伺服器控制項子系的內容輸出至提供的 HtmlTextWriter 物件,再由這個物件在用戶端上寫入要轉譯的內容。

(繼承來源 Control)
RenderContents(HtmlTextWriter)

將控制項的內容呈現在指定的寫入器。

RenderContents(HtmlTextWriter)

呈現 ListControl 控制項中的項目。

(繼承來源 ListControl)
RenderControl(HtmlTextWriter)

將伺服器控制項內容輸出至提供的 HtmlTextWriter 物件,並在啟用追蹤時儲存控制項的追蹤資訊。

(繼承來源 Control)
RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 物件,輸出伺服器控制項內容至提供的 ControlAdapter 物件。

(繼承來源 Control)
RenderEndTag(HtmlTextWriter)

將控制項的 HTML 結尾標記呈現至指定的寫入器。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
ResolveAdapter()

取得負責呈現指定之控制項的控制項配置器。

(繼承來源 Control)
ResolveClientUrl(String)

取得瀏覽器可使用的 URL。

(繼承來源 Control)
ResolveUrl(String)

將 URL 轉換為要求用戶端可使用的 URL。

(繼承來源 Control)
SaveControlState()

儲存頁面回傳至伺服器以來,所發生的任何伺服器控制項狀態變更。

(繼承來源 Control)
SaveViewState()

儲存 ListControl 衍生控制項及其內含項目的目前檢視狀態。

(繼承來源 ListControl)
SetDesignModeState(IDictionary)

設定控制項的設計階段資料。

(繼承來源 Control)
SetPostDataSelection(Int32)

設定在張貼頁面之後,ListItem 控制項的 Selected 屬性。

(繼承來源 ListControl)
SetRenderMethodDelegate(RenderMethod)

指定事件處理常式委派,以呈現伺服器控制項及其內容至其父控制項。

(繼承來源 Control)
SetTraceData(Object, Object)

使用追蹤資料機碼和追蹤資料值,設定設計階段期間追蹤呈現資料的追蹤資料。

(繼承來源 Control)
SetTraceData(Object, Object, Object)

使用追蹤的物體、追蹤資料機碼和追蹤資料值,設定設計階段期間追蹤呈現資料的追蹤資料。

(繼承來源 Control)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
TrackViewState()

標記起始點,從這個點開始追蹤並儲存 ListControl 衍生控制項的檢視狀態變更。

(繼承來源 ListControl)
ValidateDataSource(Object)

驗證資料繫結控制項繫結至的物件是該資料繫結控制項所使用的物件。

(繼承來源 DataBoundControl)
VerifyMultiSelect()

永遠擲回 HttpException 例外狀況,因為 DropDownList 控制項不支援多重選取。

VerifyMultiSelect()

判斷清單控制項是否支援多重選取模式。

(繼承來源 ListControl)

事件

CallingDataMethods

正在呼叫資料方法時發生。

(繼承來源 DataBoundControl)
CreatingModelDataSource

正在建立 ModelDataSource 物件時發生。

(繼承來源 DataBoundControl)
DataBinding

發生於伺服器控制項繫結至資料來源時。

(繼承來源 Control)
DataBound

在伺服器控制項繫結至資料來源之後發生。

(繼承來源 BaseDataBoundControl)
Disposed

發生於伺服器控制項從記憶體釋放時,這是在要求 ASP.NET 網頁時,伺服器控制項生命週期的最後階段。

(繼承來源 Control)
Init

發生於初始化伺服器控制項時,是其生命週期中的第一個步驟。

(繼承來源 Control)
Load

發生於載入伺服器控制項至 Page 物件時。

(繼承來源 Control)
PreRender

Control 物件載入之後但在呈現之前發生。

(繼承來源 Control)
SelectedIndexChanged

當清單控制項的選取項目在發佈至伺服器期間變更時發生。

(繼承來源 ListControl)
TextChanged

TextSelectedValue 屬性變更時發生。

(繼承來源 ListControl)
Unload

發生於伺服器控制項從記憶體卸載時。

(繼承來源 Control)

明確介面實作

IAttributeAccessor.GetAttribute(String)

使用指定的名稱,取得 Web 控制項的屬性。

(繼承來源 WebControl)
IAttributeAccessor.SetAttribute(String, String)

將 Web 控制項的屬性設定為指定的名稱和值。

(繼承來源 WebControl)
IControlBuilderAccessor.ControlBuilder

如需這個成員的說明,請參閱 ControlBuilder

(繼承來源 Control)
IControlDesignerAccessor.GetDesignModeState()

如需這個成員的說明,請參閱 GetDesignModeState()

(繼承來源 Control)
IControlDesignerAccessor.SetDesignModeState(IDictionary)

如需這個成員的說明,請參閱 SetDesignModeState(IDictionary)

(繼承來源 Control)
IControlDesignerAccessor.SetOwnerControl(Control)

如需這個成員的說明,請參閱 SetOwnerControl(Control)

(繼承來源 Control)
IControlDesignerAccessor.UserData

如需這個成員的說明,請參閱 UserData

(繼承來源 Control)
IDataBindingsAccessor.DataBindings

如需這個成員的說明,請參閱 DataBindings

(繼承來源 Control)
IDataBindingsAccessor.HasDataBindings

如需這個成員的說明,請參閱 HasDataBindings

(繼承來源 Control)
IExpressionsAccessor.Expressions

如需這個成員的說明,請參閱 Expressions

(繼承來源 Control)
IExpressionsAccessor.HasExpressions

如需這個成員的說明,請參閱 HasExpressions

(繼承來源 Control)
IParserAccessor.AddParsedSubObject(Object)

如需這個成員的說明,請參閱 AddParsedSubObject(Object)

(繼承來源 Control)
IPostBackDataHandler.LoadPostData(String, NameValueCollection)

處理 DropDownList 控制項的張貼資料。

IPostBackDataHandler.RaisePostDataChangedEvent()

在回傳時引發 DropDownList 控制項的事件。

擴充方法

EnablePersistedSelection(BaseDataBoundControl)
已淘汰.

啟用要保存於資料控制項中且支援選取和分頁的選項。

FindDataSourceControl(Control)

傳回與指定之控制項的資料控制項相關聯的資料來源。

FindFieldTemplate(Control, String)

傳回在指定之控制項的命名容器中所指定資料行的欄位樣板。

FindMetaTable(Control)

傳回包含資料控制項的中繼資料表物件。

適用於

另請參閱