.NET Framework 3.0
Gets or sets the field from a data source to bind to the text caption of the hyperlinks in the HyperLinkColumn.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

Syntax

```public virtual string DataTextField { get; set; }
```
```/** @property */
public String get_DataTextField ()

/** @property */
public void set_DataTextField (String value)

```
```public function get DataTextField () : String

public function set DataTextField (value : String)

```
```Not applicable.
```

Property Value

The field name from a data source to bind to the text caption of the hyperlinks in HyperLinkColumn.

Remarks

Use the DataTextField property to specify the field name from a data source to bind to the text caption of the hyperlinks in HyperLinkColumn. When the text caption is data bound to a field, the text caption of each hyperlink in the column is set with a corresponding value in the specified field. This allows you to set a different text caption for each hyperlink in the column. To specify the same text caption for each row in the column, set the Text property instead of this property.

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 you using data binding, you can specify a custom display format for the text caption of the hyperlinks by setting the DataTextFormatString property.

Example

The following example demonstrates how to use the DataTextField property to specify the field in the data source to bind to the text caption of the hyperlinks in the HyperLinkColumn.

Note:

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

```<%@ 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">

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

for (int i = 0; i < 3; i++)
{
dr = dt.NewRow();

dr[0] = i;
dr[1] = (Double)i * 1.23;

}

DataView dv = new DataView(dt);
return dv;
}

{
MyDataGrid.DataSource = CreateDataSource();
MyDataGrid.DataBind();
}

</script>

<body>

<form id="form1" runat="server">

<asp:DataGrid id="MyDataGrid"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
AutoGenerateColumns="false"
runat="server">

<Columns>

DataNavigateUrlField="IntegerValue"
DataNavigateUrlFormatString="detailspage.aspx?id={0}"
DataTextField="PriceValue"
DataTextFormatString="{0:c}"
Target="_blank"/>

</Columns>

</asp:DataGrid>

</form>

</body>
</html>

```

The following corresponding example displays the item selected in the previous example.

```<%@ 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" >
<title>Details page for DataGrid</title>
<script runat="server">

{
Label1.Text = "You selected item: " + Request.QueryString["id"];
}

</script>

<body>

<h3>Details page for DataGrid</h3>

<asp:Label id="Label1"
runat="server"/>

</body>
</html>

```

Platforms

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0