CommandField.ShowDeleteButton 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,指出是否要在 CommandField 欄位中顯示 [刪除] 按鈕。
public:
virtual property bool ShowDeleteButton { bool get(); void set(bool value); };
public virtual bool ShowDeleteButton { get; set; }
member this.ShowDeleteButton : bool with get, set
Public Overridable Property ShowDeleteButton As Boolean
屬性值
若要在 CommandField 中顯示 [刪除] 按鈕,則為 true
,否則為 false
。 預設為 false
。
範例
下列程式碼範例示範如何使用 ShowDeleteButton 屬性來顯示 控制項中每個記錄的 GridView [刪除] 按鈕。
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
datakeynames="CustomerID"
runat="server">
<columns>
<asp:commandfield showdeletebutton="true"
headertext="Edit Controls"/>
<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]"
deletecommand="Delete [Customers] Where [CustomerID] = @CustomerID"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
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">
<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:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
datakeynames="CustomerID"
runat="server">
<columns>
<asp:commandfield showdeletebutton="true"
headertext="Edit Controls"/>
<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]"
deletecommand="Delete [Customers] Where [CustomerID] = @CustomerID"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
備註
ShowDeleteButton使用 屬性可指定是否在資料來源控制項中每個記錄的欄位中顯示 CommandField [刪除] 按鈕。 [刪除] 按鈕可讓您從資料來源中移除記錄。
注意
當資料繫結控制項與資料來源控制項搭配使用時, (例如 SqlDataSource 控制項) ,資料繫結控制項可以利用資料來源控制項的功能並提供自動刪除功能。 對於其他資料來源,您必須提供常式,以在資料繫結控制項的適當事件期間執行刪除作業。
ButtonType當欄位的 CommandField 屬性設定 ButtonType.Button
為 或 ButtonType.Link
時,請使用 DeleteText 屬性來指定要顯示 [刪除] 按鈕的文字。 或者,您可以先將 屬性設定 ButtonType 為 ButtonType.Image
,然後設定 DeleteImageUrl 屬性來顯示影像。