DynamicControl.UIHint DynamicControl.UIHint DynamicControl.UIHint DynamicControl.UIHint Property

定義

取得或設定用來呈現資料欄位的欄位樣板名稱。Gets or sets the name of the field template that is used to render the data field.

public:
 virtual property System::String ^ UIHint { System::String ^ get(); void set(System::String ^ value); };
public virtual string UIHint { get; set; }
member this.UIHint : string with get, set
Public Overridable Property UIHint As String

屬性值

用來呈現資料欄位的欄位樣板名稱。The name of the field template that is used to render the data field. 預設為空字串 (""),表示欄位樣板將會根據資料欄位型別或套用於資料模型的中繼資料資訊來呈現。The default is an empty string (""), which indicates that the field template will be rendered based on the data field type or on metadata information applied to the data model.

範例

請參閱這項功能的執行時間程式碼範例:執行See a run-time code example of this feature: Run.

下列範例顯示如何指定資料欄位, 以使用不同的欄位範本來呈現其內容。The following example shows how you can specify a data field to use a different field template to render its contents. 第二個範例顯示UIHint屬性所指定的自訂欄位範本。The second example shows the custom field template specified by the UIHint property.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  protected void Page_Init(object sender, EventArgs e)
  {
    DynamicDataManager1.RegisterControl(Repeater1);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>DynamicControl.UIHint Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
        AutoLoadForeignKeys="true" />
        
      <asp:Repeater ID="Repeater1" runat="server" DataSourceID="LinqDataSource1">
        <HeaderTemplate>
          <table border="1">
            <tr>
               <th>First Name</th>
               <th>Last Name</th>
               <th>Email</th>
            </tr>        
        </HeaderTemplate>
        <ItemTemplate>
          <tr>
            <td><asp:DynamicControl runat="server" DataField="FirstName" /></td>
            <td><asp:DynamicControl runat="server" DataField="LastName" /></td>
            <td><asp:DynamicControl runat="server" DataField="EmailAddress" UIHint="Email" />&nbsp;</td>
          </tr>
        </ItemTemplate>
        <FooterTemplate>
          </table>
        </FooterTemplate>
      </asp:Repeater>

      <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
        TableName="Customers"
        ContextTypeName="AdventureWorksLTDataContext">
      </asp:LinqDataSource>
    </div>
    </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">

<script runat="server">

  Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)    
    DynamicDataManager1.RegisterControl(Repeater1)
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>DynamicControl.UIHint Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
        AutoLoadForeignKeys="true" />
        
      <asp:Repeater ID="Repeater1" runat="server" DataSourceID="LinqDataSource1">
        <HeaderTemplate>
          <table border="1">
            <tr>
               <th>First Name</th>
               <th>Last Name</th>
               <th>Email</th>
            </tr>        
        </HeaderTemplate>
        <ItemTemplate>
          <tr>
            <td><asp:DynamicControl runat="server" DataField="FirstName" /></td>
            <td><asp:DynamicControl runat="server" DataField="LastName" /></td>
            <td><asp:DynamicControl runat="server" DataField="EmailAddress" UIHint="Email" />&nbsp;</td>
          </tr>
        </ItemTemplate>
        <FooterTemplate>
          </table>
        </FooterTemplate>
      </asp:Repeater>

      <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
        TableName="Customers"
        ContextTypeName="AdventureWorksLTDataContext">
      </asp:LinqDataSource>
    </div>
    </form>
</body>
</html>
<%@ Control Language="C#" ClassName="Email" Inherits="System.Web.DynamicData.FieldTemplateUserControl"%>

<script runat="server">
  protected string GetNavigateUrl()
  {
    if (!String.IsNullOrEmpty(FieldValueString))
    {
      return "mailto:" + FieldValueString;
    }

    return string.Empty;
  }
</script>

<asp:HyperLink ID="EmailAddressLink" runat="server"
    Text="<%# FieldValueString %>"
    NavigateUrl="<%# GetNavigateUrl() %>"  />
<%@ Control Language="VB" ClassName="Email" Inherits="System.Web.DynamicData.FieldTemplateUserControl"%>

<script runat="server">
    
    Protected Function GetNavigateUrl() As String

        If (Not String.IsNullOrEmpty(FieldValueString)) Then
            Return "mailto:" & FieldValueString
        End If
    
        Return String.Empty

    End Function
    
</script>

<asp:HyperLink ID="EmailAddressLink" runat="server"
    Text="<%# FieldValueString %>"
    NavigateUrl="<%# GetNavigateUrl() %>"  />

備註

UIHint使用屬性, 即可指定要用來顯示資料欄位之 UI 的欄位範本。Use the UIHint property to specify the field template to use to display the UI for a data field. 欄位範本預設為使用者控制項, 其名稱包含尾碼, 用以識別用於編輯作業和插入作業的欄位範本。Field templates by default are user controls and their names contain a suffix to identify field templates that are used for edit operations and insert operations. 尾碼分別為 [編輯] 和 [_insert]。The suffixes are _edit and _insert, respectively. 當您將值設定為UIHint屬性時, 您可以設定不含尾碼的名稱。When you set a value to the UIHint property, you set the name without the suffixes. 動態資料會藉由評估Mode屬性值來識別正確的模式, 並將轉譯正確的欄位範本。Dynamic Data will identify the correct mode by evaluating the Mode property value and will render the correct field template.

如果未設定屬性, 根據預設, 動態資料會根據欄位類型轉譯欄位範本。 UIHintIf the UIHint property is not set, by default Dynamic Data will render the field template based on the field type. 如需詳細資訊, 請參閱ASP.NET 動態資料的樣板。For more information, see ASP.NET Dynamic Data Scaffolding.

您使用UIHint屬性指定的欄位範本, 是這個DynamicControl控制項實例特有的。The field template that you specify using the UIHint property is specific to this instance of the DynamicControl control. 您也可以藉由UIHintAttribute將套用至資料模型, 在整個應用程式中變更資料欄位所使用的欄位範本。You can also change the field template used by a data field across the entire application by applying the UIHintAttribute to your data model. UIHint設定屬性會覆寫套用至資料模型的中繼資料。Setting the UIHint property overrides the metadata applied to the data model. 如需中繼資料屬性的詳細資訊, 請參閱ASP.NET 動態資料For more information about metadata attributes, see ASP.NET Dynamic Data.

適用於

另請參閱