다음을 통해 공유


ButtonField.ImageUrl 속성

정의

ButtonField 개체의 각 단추에 표시할 이미지를 가져오거나 설정합니다.

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

속성 값

String

ButtonField의 각 단추에 표시할 이미지입니다. 기본값은 빈 문자열("")로, ImageUrl 속성이 설정되지 않았음을 나타냅니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 ImageUrl 속성의 각 단추에 표시할 이미지를 지정 하는 ButtonField 개체입니다. 표시 하려면이 코드 예제를 사용자 고유의 이미지를 제공 해야 합니다.


<%@ 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 lastNameCell = selectedRow.Cells[1];
      string lastName = lastNameCell.Text;  
    
      // Display the selected author.
      Message.Text = "You selected " + lastName + ".";
      
    }
    
  }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ButtonField ImageUrl Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ButtonField ImageUrl Example</h3>
      
      <asp:label id="Message"
        forecolor="Red"
        runat="server"
        AssociatedControlID="CustomersGridView"/>
                    
      <!-- Set the ImageUrl property of the ButtonField declaratively. -->
      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="false"
        onrowcommand="CustomersGridView_RowCommand"
        runat="server">
                
        <columns>
                
          <asp:buttonfield buttontype="Image" 
            commandname="Select"
            headertext="Select Author"
            ImageUrl="~\images\ButtonImage.jpg"/>
          <asp:boundfield datafield="ContactName" 
            headertext="ContactName"/>
          <asp:boundfield datafield="ContactTitle" 
            headertext="ContactTitle"/>
                
        </columns>
                
      </asp:gridview>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Northwind sample database.                   -->
        <asp:sqldatasource id="CustomersSqlDataSource"  
          selectcommand="Select [CustomerID], [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 lastNameCell As TableCell = selectedRow.Cells(1)
      Dim lastName As String = lastNameCell.Text
    
      ' Display the selected author.
      Message.Text = "You selected " & lastName & "."
      
    End If
    
  End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ButtonField ImageUrl Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ButtonField ImageUrl Example</h3>
      
      <asp:label id="Message"
        forecolor="Red"
        runat="server"
        AssociatedControlID="CustomersGridView"/>
                    
      <!-- Set the ImageUrl property of the ButtonField declaratively. -->
      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="false"
        onrowcommand="CustomersGridView_RowCommand"
        runat="server">
                
        <columns>
                
          <asp:buttonfield buttontype="Image" 
            commandname="Select"
            headertext="Select Author"
            ImageUrl="~\images\ButtonImage.jpg"/>
          <asp:boundfield datafield="ContactName" 
            headertext="ContactName"/>
          <asp:boundfield datafield="ContactTitle" 
            headertext="ContactTitle"/>
                
        </columns>
                
      </asp:gridview>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Northwind sample database.                   -->
        <asp:sqldatasource id="CustomersSqlDataSource"  
          selectcommand="Select [CustomerID], [ContactName], [ContactTitle] From [Customers]"
          connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
          runat="server">
        </asp:sqldatasource>
            
    </form>
  </body>
</html>

설명

경우는 ButtonType 의 속성을 ButtonField 개체로 설정 됩니다는 Image 값을 사용 하 여는 ImageUrl 각 단추에 대해 표시할 이미지를 지정 하는 속성. 이 이미지는 클라이언트 브라우저에서 해당 형식으로 모든 파일 형식 (.jpg,.gif,.bmp, 및 등) 수 있습니다.

이 속성의 값은 뷰 상태에 저장 됩니다.

적용 대상