CommandField.SelectText Property
Gets or sets the caption for a Select button in a CommandField field.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Property Value
Type: System.StringThe caption for a Select button in a CommandField. The default is "Select".
When the ButtonType property of a CommandField field is set to ButtonType.Button or ButtonType.Link, use the SelectText property to specify the text to display for a Select button.
Note |
|---|
As an alternative to displaying text for a Select button, you can display an image by first setting the ButtonType property to ButtonType.Image and then setting the SelectImageUrl property. |
The value of this property, when set, can be saved automatically to a resource file by using a designer tool. For more information, see LocalizableAttribute and ASP.NET Globalization and Localization.
The following code example demonstrates how to use the SelectText property to specify a custom caption for a Select button displayed in a CommandField field of a GridView control.
<%@ 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_SelectedIndexChanged(Object sender, EventArgs e) { // Retrieve the company name from the appropriate cell. String companyName = CustomersGridView.SelectedRow.Cells[2].Text; // Display company name selected by the user. Message.Text = "You selected " + companyName + "."; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>CommandField Example</title> </head> <body> <form id="form1" runat="server"> <h3>CommandField Example</h3> <asp:Label id="Message" forecolor="Red" runat="server"/> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="false" datakeynames="CustomerID" onselectedindexchanged="CustomersGridView_SelectedIndexChanged" runat="server"> <columns> <asp:commandfield showselectbutton="true" selecttext="Pick" headertext="Select Customer"/> <asp:boundfield datafield="CustomerID" headertext="Customer ID" /> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="Address" headertext="Address"/> <asp:boundfield datafield="City" headertext="City"/> <asp:boundfield datafield="PostalCode" headertext="ZIP Code"/> <asp:boundfield datafield="Country" headertext="Country"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note