Export (0) Print
Expand All

DynamicControl.UIHint Property

Gets or sets the name of the field template that is used to render the data field.

Namespace:  System.Web.DynamicData
Assembly:  System.Web.DynamicData (in System.Web.DynamicData.dll)

public virtual string UIHint { get; set; }
<asp:DynamicControl UIHint="String" />

Property Value

Type: System.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.

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. The suffixes are _edit and _insert, respectively. When you set a value to the UIHint property, you set the name without the suffixes. Dynamic Data will identify the correct mode by evaluating the Mode property value and will render the correct field template.

If the UIHint property is not set, by default Dynamic Data will render the field template based on the field type. For more information, see ASP.NET Dynamic Data Scaffolding.

The field template that you specify using the UIHint property is specific to this instance of the DynamicControl control. You can also change the field template used by a data field across the entire application by applying the UIHintAttribute to your data model. Setting the UIHint property overrides the metadata applied to the data model. For more information about metadata attributes, see ASP.NET Dynamic Data.

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. 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>E-mail</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() %>"  />

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft