ButtonField.DataTextField Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee haalt u de naam op van het gegevensveld waarvoor de waarde is gebonden aan de Text eigenschap van het Button besturingselement dat door het ButtonField object wordt weergegeven.
public:
virtual property System::String ^ DataTextField { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual string DataTextField { get; set; }
[System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual string DataTextField { get; set; }
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.DataTextField : string with get, set
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.DataTextField : string with get, set
Public Overridable Property DataTextField As String
Waarde van eigenschap
De naam van het veld dat moet worden gekoppeld aan de ButtonField. De standaardwaarde is een lege tekenreeks (""), die aangeeft dat de DataTextField eigenschap niet is ingesteld.
- Kenmerken
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u de DataTextField eigenschap gebruikt om op te geven welk veld moet worden weergegeven in een ButtonField kolom van een GridView besturingselement.
<%@ 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">
void AuthorsGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
// If multiple ButtonField column fields are used, use the
// CommandName property to determine which button was clicked.
if(e.CommandName=="Select")
{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32(e.CommandArgument);
// Get the last name of the selected author from the appropriate
// cell in the GridView control.
GridViewRow selectedRow = AuthorsGridView.Rows[index];
TableCell lastNameCell = selectedRow.Cells[1];
string lastName = lastNameCell.Text;
// Display the selected author.
Message.Text = "You selected " + lastName + ".";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ButtonField DataTextField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ButtonField DataTextField Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"
AssociatedControlID="AuthorsGridView"/>
<!-- Set the DataTextField property of the ButtonField -->
<!-- declaratively. Set the DataTextFormatString -->
<!-- property to apply special formatting to the text. -->
<asp:gridview id="AuthorsGridView"
datasourceid="AuthorsSqlDataSource"
autogeneratecolumns="false"
onrowcommand="AuthorsGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Link"
commandname="Select"
headertext="Select Author"
datatextfield="au_lname"
datatextformatstring="[{0}]"
text="Select"/>
<asp:boundfield datafield="au_fname"
headertext="First Name"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Pubs sample database. -->
<asp:sqldatasource id="AuthorsSqlDataSource"
selectcommand="SELECT [au_lname], [au_fname] FROM [authors]"
connectionstring="server=localhost;database=pubs;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</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">
Sub AuthorsGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
' If multiple ButtonField column fields are used, use the
' CommandName property to determine which button was clicked.
If e.CommandName = "Select" Then
' Convert the row index stored in the CommandArgument
' property to an Integer.
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
' Get the last name of the selected author from the appropriate
' cell in the GridView control.
Dim selectedRow As GridViewRow = AuthorsGridView.Rows(index)
Dim lastNameCell As TableCell = selectedRow.Cells(1)
Dim lastName As String = lastNameCell.Text
' Display the selected author.
Message.Text = "You selected " & lastName & "."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ButtonField DataTextField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ButtonField DataTextField Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"
AssociatedControlID="AuthorsGridView"/>
<!-- Set the DataTextField property of the ButtonField -->
<!-- declaratively. Set the DataTextFormatString -->
<!-- property to apply special formatting to the text. -->
<asp:gridview id="AuthorsGridView"
datasourceid="AuthorsSqlDataSource"
autogeneratecolumns="false"
onrowcommand="AuthorsGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Link"
commandname="Select"
headertext="Select Author"
datatextfield="au_lname"
datatextformatstring="[{0}]"
text="Select"/>
<asp:boundfield datafield="au_fname"
headertext="First Name"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Pubs sample database. -->
<asp:sqldatasource id="AuthorsSqlDataSource"
selectcommand="SELECT [au_lname], [au_fname] FROM [authors]"
connectionstring="server=localhost;database=pubs;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
Opmerkingen
Wanneer de ButtonType eigenschap van een ButtonField object is ingesteld op de Button of Link waarde, gebruikt u de DataTextField eigenschap om de naam van het veld op te geven dat aan het ButtonField object moet worden gekoppeld. De waarden van het veld worden vervolgens weergegeven als de tekst voor de knoppen in het ButtonField object. U kunt de weergegeven tekst desgewenst opmaken door de DataTextFormatString eigenschap in te stellen.
In plaats van de DataTextField eigenschap te gebruiken om een object te binden aan een ButtonField veld uit een gegevensbron, kunt u de Text eigenschap gebruiken om statische tekst weer te geven voor de tekst van de knoppen in het ButtonField object. Wanneer de Text eigenschap wordt gebruikt, deelt elke knop hetzelfde bijschrift.
Note
Als de DataTextField eigenschappen Text beide zijn ingesteld, heeft de DataTextField eigenschap voorrang.
De waarde van deze eigenschap wordt opgeslagen in de weergavestatus.