System.Web.UI.WebControls Namespace HyperLinkField Class
.NET Framework version 2.0
Sets or retrieves the field from a data source to bind to the text caption of the hyperlinks in a HyperLinkField.
Inline |
<asp:hyperlinkfield datatextfield = strFieldName ... > |
Script |
HyperLinkField.DataTextField = strFieldName |
strFieldName |
String specifying the name of a field from the data source to bind to the text caption of the hyperlinks in the column. |
The property is read/write with no default value.
Use the DataTextField property to specify or determine the field name from a data source to bind to the text caption of the hyperlinks in a HyperLinkField.
NOTE: The specified field name must point to a field in the data source bound to the column's parent control, such as the GridView control. The properties of a HyperLinkField cannot be bound to a data source other than the parent control's data source.
When this property is set, the caption for each hyperlink in the column is set to the corresponding row value in the specified field from the data source bound to the parent control. This allows setting a different text caption for each hyperlink in the column. To specify the same caption for all hyperlinks, set the Text property instead.
NOTE: The DataTextField and Text properties cannot both be set at the same time. If both properties are set, the DataTextField property takes precedence.
When using data binding, you can specify a custom display format for the hyperlink captions by setting the DataTextFormatString property.
The following example demonstrates how to set the DataTextField property to dynamically display different text captions in a HyperLinkField at run time.
<asp:hyperlinkfield headertext = "Title"
datatextfield = "title"
datanavigateurlformatstring = "details_title.aspx?titleid={0}"
datanavigateurlfields = "title_id" />
HyperLinkField Members Adding HyperLink Fields to a GridView Control