共用方式為


CommandField.DeleteImageUrl 屬性

定義

取得或設定要為 CommandField 欄位中 [刪除] 按鈕顯示之影像的 URL。

public:
 virtual property System::String ^ DeleteImageUrl { System::String ^ get(); void set(System::String ^ value); };
public virtual string DeleteImageUrl { get; set; }
member this.DeleteImageUrl : string with get, set
Public Overridable Property DeleteImageUrl As String

屬性值

要為 CommandField 中 [刪除] 按鈕顯示之影像的 URL。 預設為空字串 (""),表示這個屬性未設定。

範例

下列程式碼範例示範如何使用 DeleteImageUrl 屬性來指定要在控制項欄位中顯示 [刪除] 按鈕 CommandFieldGridView 自訂影像。 屬性 ButtonType 必須設定 ButtonType.Image 為 ,[刪除] 按鈕才能顯示影像。


<%@ 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"
            buttontype="Image"
            deleteimageurl="~\Images\DeleteImage.jpg"
            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"
            buttontype="Image"
            deleteimageurl="~\Images\DeleteImage.jpg"
            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>

備註

ButtonType當欄位的 CommandField 屬性設定 ButtonType.Image 為 時,請使用 DeleteImageUrl 屬性指定要顯示 [刪除] 按鈕的影像。 只要用戶端的瀏覽器支援該格式,此影像就可以是任何檔案格式 (.jpg、.gif、.bmp等等) 。

注意

除了顯示 [刪除] 按鈕的影像,您也可以先將 屬性設定 ButtonTypeButtonType.ButtonButtonType.Link ,然後設定 DeleteText 屬性來顯示文字。

適用於

另請參閱