DetailsView.DataItemCount 속성

정의

내부 데이터 소스의 항목 수를 가져옵니다.

public:
 property int DataItemCount { int get(); };
[System.ComponentModel.Browsable(false)]
public int DataItemCount { get; }
[<System.ComponentModel.Browsable(false)>]
member this.DataItemCount : int
Public ReadOnly Property DataItemCount As Integer

속성 값

Int32

내부 데이터 소스의 항목 수입니다.

특성

예제

다음 코드 예제에서는 속성을 사용 하 여 DataItemCount 데이터 소스의 항목 수를 확인 하는 방법을 보여 줍니다. 이 값은 사용자 지정 호출기 행 내에 포함된 컨트롤의 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">

    protected void CustomerDetailView_DataBound(object sender, EventArgs e)
    {

      // Get the pager row.
      DetailsViewRow pagerRow = CustomerDetailView.BottomPagerRow;

      // Get the Label controls that display the current page information 
      // from the pager row.
      Label pageNum = (Label)pagerRow.Cells[0].FindControl("PageNumberLabel");
      Label totalNum = (Label)pagerRow.Cells[0].FindControl("TotalPagesLabel");

      if ((pageNum != null) && (totalNum != null))
      {
          // Update the Label controls with the current page values.
          int page = CustomerDetailView.DataItemIndex + 1;
          int count = CustomerDetailView.DataItemCount;

          pageNum.Text = page.ToString();
          totalNum.Text = count.ToString();
      }
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>DetailsView PagerTemplate Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView PagerTemplate Example</h3>
                
        <!-- Notice that the LinkButton controls in the pager   -->
        <!-- template have their CommandName properties set.    -->
        <!-- The DetailsView control automatically recognizes   -->
        <!-- certain command names and performs the appropriate -->
        <!-- operation. In this example, the CommandName        -->
        <!-- properties are set "Page" and the CommandArgument  -->
        <!-- properties are set to "Next" and "Prev", which     -->
        <!-- causes the DetailsView control to navigate to the  -->
        <!-- next and previous record, respectively.            -->        
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true" 
          allowpaging="true"
        
          runat="server" OnDataBound="CustomerDetailView_DataBound">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
            
          <pagerstyle VerticalAlign="Bottom" />
            
          <pagertemplate>
          
            <table width="100%">
              <tr>
                <td>
                  <asp:LinkButton id="PreviousButton"
                    text="<"
                    CommandName="Page"
                    CommandArgument="Prev"
                    runat="Server"/>
                  <asp:LinkButton id="NextButton"
                    text=">"
                    CommandName="Page"
                    CommandArgument="Next"
                    runat="Server"/> 
                </td>
                <td align="right">                
                  Page <asp:Label id="PageNumberLabel" runat="server" /> 
                  of <asp:Label id="TotalPagesLabel" runat="server" />                
                </td>
              </tr>
            </table>          
          </pagertemplate>   
                    
        </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">

    Protected Sub CustomerDetailView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
        ' Get the pager row.
        Dim pagerRow As DetailsViewRow = CustomerDetailView.BottomPagerRow

        ' Get the Label controls that display the current page information 
        ' from the pager row.
        Dim pageNum As Label = CType(pagerRow.Cells(0).FindControl("PageNumberLabel"), Label)
        Dim totalNum As Label = CType(pagerRow.Cells(0).FindControl("TotalPagesLabel"), Label)
        
        If (pageNum IsNot Nothing) And (totalNum IsNot Nothing) Then
            ' Update the Label controls with the current page values.
            Dim page As Integer = CustomerDetailView.DataItemIndex + 1
            Dim count As Integer = CustomerDetailView.DataItemCount

            pageNum.Text = page.ToString()
            totalNum.Text = count.ToString()
        End If
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>DetailsView PagerTemplate Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView PagerTemplate Example</h3>
                
        <!-- Notice that the LinkButton controls in the pager   -->
        <!-- template have their CommandName properties set.    -->
        <!-- The DetailsView control automatically recognizes   -->
        <!-- certain command names and performs the appropriate -->
        <!-- operation. In this example, the CommandName        -->
        <!-- properties are set "Page" and the CommandArgument  -->
        <!-- properties are set to "Next" and "Prev", which     -->
        <!-- causes the DetailsView control to navigate to the  -->
        <!-- next and previous record, respectively.            -->        
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true" 
          allowpaging="true"
        
          runat="server" OnDataBound="CustomerDetailView_DataBound">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
            
          <pagerstyle VerticalAlign="Bottom" />
            
          <pagertemplate>
          
            <table width="100%">
              <tr>
                <td>
                  <asp:LinkButton id="PreviousButton"
                    text="<"
                    CommandName="Page"
                    CommandArgument="Prev"
                    runat="Server"/>
                  <asp:LinkButton id="NextButton"
                    text=">"
                    CommandName="Page"
                    CommandArgument="Next"
                    runat="Server"/> 
                </td>
                <td align="right">                
                  Page <asp:Label id="PageNumberLabel" runat="server" /> 
                  of <asp:Label id="TotalPagesLabel" runat="server" />                
                </td>
              </tr>
            </table>          
          </pagertemplate>   
                    
        </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>

설명

페이징 기능을 사용하도록 설정하면(속성을 설정하여 AllowPaging ) 속성을 true사용하여 DataItemCount 기본 데이터 원본의 총 레코드 수를 확인합니다.

참고

컨트롤은 DetailsView 한 번에 하나의 레코드만 표시하므로 이 값은 데이터 원본의 모든 레코드를 표시하는 데 필요한 총 페이지 수에 해당합니다.

기본 데이터 원본에서 현재 레코드의 인덱스 확인 하려면 속성을 사용 합니다 DataItemIndex .

적용 대상

추가 정보