Prop Webcontrol Listcontrol Datatextfield
## ASP.NET DataTextField Property
The `DataTextField` property is a key member of the `ListControl` class in ASP.NET. It specifies which field or column from the data source should be bound to the **Text** property of each item in the list control.
---
## Definition and Usage
When binding a list control (such as `DropDownList`, `ListBox`, `RadioButtonList`, or `CheckBoxList`) to a data source (like a `DataSet`, `SqlDataReader`, or `List`), you need to map the data source fields to the control's items.
* **`DataTextField`**: Determines the text that is displayed to the user in the list control.
* **`DataValueField`**: Determines the hidden value associated with that text (typically an ID or key).
If the `DataTextField` property is not specified, the control will default to displaying the string representation of the data source objects (usually by calling their `ToString()` method).
---
## Syntax
```syntax
```
### Property Value
* **`DataSourceField`**: A string representing the name of the field/column in the data source to bind to the `Text` property of each item.
---
## Code Example
The following example demonstrates how to bind a `RadioButtonList` control to an external XML data source using the `DataTextField` and `DataValueField` properties.
### The XML Data Source (`countries.xml`)
This is the structure of the XML file used in the example:
```xml
Norway
NO
Sweden
SE
France
FR
Italy
IT
```
### ASP.NET Page (`Default.aspx`)
```asp
<%@ Import Namespace="System.Data" %>
ASP.NET DataTextField Example
```
---
## Key Considerations
1. **Data Binding Requirement**: Setting the `DataTextField` property only configures the mapping. The data binding does not occur until you explicitly call the `DataBind()` method on the control or its parent container (e.g., `Page.DataBind()`).
2. **Case Sensitivity**: Ensure that the string assigned to `DataTextField` matches the exact spelling and casing of the column or property name in your data source to avoid runtime binding errors.
3. **Formatting**: If you need to format the displayed text (such as formatting currency, dates, or custom strings), you can use the companion property **`DataTextFormatString`** alongside `DataTextField`.
YouTip