ButtonField.DataTextField Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lekéri vagy beállítja annak az adatmezőnek a nevét, amelyhez az érték az objektum által Text renderelt vezérlőelem tulajdonságához Button van kötveButtonField.
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
Tulajdonság értéke
Annak a mezőnek a neve, amely a ButtonField. Az alapértelmezett érték egy üres sztring (""), amely azt jelzi, hogy a DataTextField tulajdonság nincs beállítva.
- Attribútumok
Példák
Az alábbi példakód bemutatja, hogyan használható a tulajdonság a DataTextField vezérlőelem oszlopában ButtonFieldGridView megjelenítendő mező megadására.
<%@ 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>
Megjegyzések
Ha egy ButtonTypeButtonField objektum tulajdonsága az vagy Button az Link értékre van állítva, a DataTextField tulajdonság használatával adja meg az objektumhoz ButtonField kötéshez szükséges mező nevét. A mező értékei ekkor az objektum gombjainak ButtonField szövegeként jelennek meg. Igény szerint a tulajdonság beállításával formázhatja a DataTextFormatString megjelenített szöveget.
Ahelyett, hogy a DataTextField tulajdonságot használva egy objektumot egy adatforrásból származó mezőhöz köt ButtonField , a Text tulajdonsággal statikus szöveget jeleníthet meg az objektum gombjainak ButtonField szövegéhez. A Text tulajdonság használatakor minden gomb ugyanazt a feliratot használja.
Note
Ha a tulajdonságok és DataTextField a Text tulajdonságok is be vannak állítva, a DataTextField tulajdonság elsőbbséget élvez.
Ennek a tulajdonságnak az értéke megtekintési állapotban van tárolva.