ButtonField.Text Propriedade
Definição
Obtém ou define a legenda estática exibida para cada botão no objeto ButtonField.Gets or sets the static caption that is displayed for each button in the ButtonField object.
public:
virtual property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public virtual string Text { get; set; }
member this.Text : string with get, set
Public Overridable Property Text As String
Valor da propriedade
A legenda exibida para cada botão no ButtonField.The caption displayed for each button in the ButtonField. O padrão é uma cadeia de caracteres vazia ("").The default is an empty string ("").
Exemplos
O exemplo de código a seguir demonstra como usar a Text propriedade para especificar a legenda a ser exibida para cada botão em um ButtonField objeto.The following code example demonstrates how to use the Text property to specify the caption to display for each button in a ButtonField object.
<%@ 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 CustomersGridView_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 = CustomersGridView.Rows[index];
TableCell contactName = selectedRow.Cells[1];
string contact = contactName.Text;
// Display the selected author.
Message.Text = "You selected " + contact + ".";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ButtonField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ButtonField Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"
AssociatedControlID="CustomersGridView"/>
<!-- Populate the Columns collection declaratively. -->
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
onrowcommand="CustomersGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Button"
commandname="Select"
headertext="Select Customer"
text="Select"/>
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="ContactName"
headertext="Contact Name"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
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 CustomersGridView_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 = CustomersGridView.Rows(index)
Dim contactCell As TableCell = selectedRow.Cells(1)
Dim contact As String = contactCell.Text
' Display the selected author.
Message.Text = "You selected " & contact & "."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ButtonField Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>ButtonField Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"
AssociatedControlID="CustomersGridView"/>
<!-- Populate the Columns collection declaratively. -->
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
onrowcommand="CustomersGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Button"
commandname="Select"
headertext="Select Customer"
text="Select"/>
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="ContactName"
headertext="Contact Name"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
Comentários
Quando a ButtonType propriedade de um ButtonField objeto é definida como o Button Link valor ou, use a Text propriedade para exibir o texto estático da legenda dos botões no ButtonField .When the ButtonType property of a ButtonField object is set to the Button or Link value, use the Text property to display static text for the caption of the buttons in the ButtonField. Cada botão compartilha a mesma legenda.Each button shares the same caption.
Em vez de usar a Text propriedade para exibir texto estático em um ButtonField objeto, você pode usar a DataTextField propriedade para associar o ButtonField a um campo em uma fonte de dados.Instead of using the Text property to display static text in a ButtonField object, you can use the DataTextField property to bind the ButtonField to a field in a data source. Os valores do campo são exibidos como a legenda dos botões.The values of the field are then displayed as the caption of the buttons.
Observação
Se as DataTextField Text Propriedades e estiverem definidas, a DataTextField Propriedade terá precedência.If the DataTextField and Text properties are both set, the DataTextField property takes precedence.
O valor dessa propriedade é armazenado em estado de exibição.The value of this property is stored in view state.
O valor dessa propriedade, quando definido, pode ser salvo automaticamente em um arquivo de recurso usando uma ferramenta de designer.The value of this property, when set, can be saved automatically to a resource file by using a designer tool. Para obter mais informações, consulte, LocalizableAttribute globalização e localização.For more information, see LocalizableAttribute and Globalization and Localization.