CommandField.SelectText 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 CommandField 欄位中 [選取] 按鈕的標題。
public:
virtual property System::String ^ SelectText { System::String ^ get(); void set(System::String ^ value); };
public virtual string SelectText { get; set; }
member this.SelectText : string with get, set
Public Overridable Property SelectText As String
屬性值
CommandField 中 [選取] 按鈕的標題。 預設值為 [選取]。
範例
下列程式代碼範例示範如何使用 SelectText 屬性來指定控件欄位中所顯示 CommandField [選取] 按鈕的 GridView 自定義標題。
<%@ 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>
<%@ Page language="VB" AutoEventWireup="False" %>
<!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_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles CustomersGridView.SelectedIndexChanged
' Retrieve the company name from the appropriate cell.
Dim companyName As String = CustomersGridView.SelectedRow.Cells(2).Text
' Display company name selected by the user.
Message.Text = "You selected " & companyName & "."
End Sub
</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"
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>
備註
ButtonType當欄位的 CommandField 屬性設定ButtonType.Button
為 或 ButtonType.Link
時,請使用 SelectText 屬性指定要顯示 [選取] 按鈕的文字。
注意
除了顯示 [選取] 按鈕的文字,您也可以先將 屬性設定 ButtonType 為 ButtonType.Image
,然後設定 SelectImageUrl 屬性來顯示影像。
當設定時,此屬性的值可以使用設計工具自動儲存到資源檔。 如需詳細資訊,請參閱 LocalizableAttribute和全球化和當地語系化。