다음을 통해 공유


DetailsView.HeaderRow 속성

정의

DetailsViewRow 컨트롤의 머리글 행을 나타내는 DetailsView 개체를 가져옵니다.

public:
 virtual property System::Web::UI::WebControls::DetailsViewRow ^ HeaderRow { System::Web::UI::WebControls::DetailsViewRow ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual System.Web.UI.WebControls.DetailsViewRow HeaderRow { get; }
[<System.ComponentModel.Browsable(false)>]
member this.HeaderRow : System.Web.UI.WebControls.DetailsViewRow
Public Overridable ReadOnly Property HeaderRow As DetailsViewRow

속성 값

DetailsViewRow 컨트롤의 머리글 행을 나타내는 DetailsView입니다.

특성

예제

다음 코드 예제를 사용 하는 방법을 보여 줍니다는 HeaderRow 이벤트 중에 ItemCreated 컨트롤의 헤더 행에 DetailsView 액세스 하는 속성입니다. Label 그러면 사용자 지정 머리글 행 내의 컨트롤이 현재 페이지 번호로 업데이트됩니다.


<%@ 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 CustomerDetailView_ItemCreated(Object sender, EventArgs e)
  {
    
    // Get the header row.
      DetailsViewRow headerRow = CustomerDetailView.HeaderRow;

    // Get the Label control that displays the current page information 
    // from the header row.
    Label pageNum = (Label)headerRow.FindControl("PageNumberLabel");

    if(pageNum != null)
    {
      // Update the Label control with the current page number.
        int page = CustomerDetailView.DataItemIndex + 1;
      pageNum.Text = "Page " + page.ToString ();
    }
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView HeaderTemplate Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView HeaderTemplate Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          allowpaging="true"
          onitemcreated="CustomerDetailView_ItemCreated"   
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
            
          <pagersettings Mode="NextPreviousFirstLast"/>  
            
          <headertemplate>
          
            <table width="100%">            
              <tr>
                <td align="left">
                  <asp:Image id="LogoImage"
                    imageurl="~\images\Logo.jpg"
                    AlternateText="Our logo" 
                    runat="server"/>
                </td>
                <td align="right" valign="bottom">
                  <asp:Label id="PageNumberLabel"
                    font-size="9"
                    forecolor="DodgerBlue"
                    runat="server"/>
                </td>
              </tr>            
            </table>
          
          </headertemplate>
                    
        </asp:detailsview>
        
        <!-- 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="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
          InsertCommand="INSERT INTO [Customers]([CustomerID],
            [CompanyName], [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"

          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </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 CustomerDetailView_ItemCreated(ByVal sender As Object, _
        ByVal e As EventArgs)
        ' Get the header row.
        Dim headerRow As DetailsViewRow = CustomerDetailView.HeaderRow

        ' Get the Label control that displays the current page information 
        ' from the header row.
        Dim pageNum As Label = _
            CType(headerRow.FindControl("PageNumberLabel"), Label)

        If Not pageNum Is Nothing Then
    
            ' Update the Label control with the current page number.
            Dim page As Integer = CustomerDetailView.DataItemIndex + 1
            pageNum.Text = "Page " & page.ToString()
    
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView HeaderTemplate Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView HeaderTemplate Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          allowpaging="true"
          onitemcreated="CustomerDetailView_ItemCreated"   
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
            
          <pagersettings Mode="NextPreviousFirstLast"/>  
            
          <headertemplate>
          
            <table width="100%">            
              <tr>
                <td align="left">
                  <asp:Image id="LogoImage"
                    imageurl="~\images\Logo.jpg"
                    AlternateText="Our logo" 
                    runat="server"/>
                </td>
                <td align="right" valign="bottom">
                  <asp:Label id="PageNumberLabel"
                    font-size="9"
                    forecolor="DodgerBlue"
                    runat="server"/>
                </td>
              </tr>            
            </table>
          
          </headertemplate>
                    
        </asp:detailsview>
        
        <!-- 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="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
          InsertCommand="INSERT INTO [Customers]([CustomerID],
            [CompanyName], [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"

          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>

설명

머리글 행은 또는 HeaderTemplate 속성이 DetailsView 설정될 때 HeaderText 컨트롤의 맨 위에 표시됩니다. 사용 된 HeaderRow 속성을 프로그래밍 방식으로 헤더 행을 DetailsViewRow 나타내는 개체에 액세스 합니다.

참고

속성은 HeaderRow 컨트롤이 이벤트에서 헤더 행 ItemCreatedDetailsView 만든 후에만 사용할 수 있습니다.

이 속성은 헤더 행을 프로그래밍 방식으로 조작해야 하는 경우(예: 사용자 지정 콘텐츠를 추가할 때) 일반적으로 사용됩니다. 컨트롤이 HeaderRow 렌더링된 후에 DetailsView 는 속성을 수정해야 합니다. 그렇지 않으면 컨트롤이 DetailsView 변경 내용을 덮어쓰게 됩니다.

적용 대상

추가 정보