DynamicControl.UIHint 属性
定义
获取或设置用于呈现数据字段的字段模板的名称。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" /> </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" /> </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. 后缀分别 _edit 和 _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.
如果 UIHint 未设置该属性,则默认情况下动态数据将基于字段类型呈现字段模板。If 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.