Repeater.DataSourceID 속성

정의

ID 컨트롤이 해당 데이터 소스를 검색하기 위해 사용해야 하는 데이터 소스 컨트롤의 Repeater 속성을 가져오거나 설정합니다.

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

속성 값

String

데이터 소스 컨트롤의 ID 속성입니다.

예외

다음과 같은 이유 중 하나로 인해 데이터 소스를 확인할 수 없는 경우

예제

다음 코드 예제에서는 컨트롤의 속성에 DataSourceID 속성을 설정 하는 ID 방법을 보여 줍니다 SqlDataSource . 페이지가 로드되면 Repeater 컨트롤이 컨트롤에 지정된 데이터 원본에 SqlDataSource 바인딩되고 데이터가 사용자에게 표시됩니다.

<%@ 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>
    <title>Repeater.DataSourceID Property Example</title>
</head>

  <body>
    <form id="Form1" runat="server">
        
      <h3>Repeater.DataSourceID Property Example</h3>
      
      <asp:repeater id="Repeater1"       
        datasourceid="SqlDataSource1"
        runat="server">
        
        <headertemplate>
          <table border="1">
            <tr>
              <td><b>Product ID</b></td>
              <td><b>Product Name</b></td>
            </tr>
        </headertemplate>
          
        <itemtemplate>
          <tr>
            <td> <%# Eval("ProductID") %> </td>
            <td> <%# Eval("ProductName") %> </td>
          </tr>
        </itemtemplate>
          
        <footertemplate>
          </table>
        </footertemplate>
      </asp:repeater>
        
            <asp:sqldatasource id="SqlDataSource1"          
            connectionstring="<%$ ConnectionStrings:NorthWindConnection%>" 
        selectcommand="SELECT ProductID, ProductName FROM [Products] Where ProductID <= 10"
        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>
    <title>Repeater.DataSourceID Property Example</title>
</head>

  <body>
    <form id="Form1" runat="server">
        
      <h3>Repeater.DataSourceID Property Example</h3>
      
      <asp:repeater id="Repeater1"       
        datasourceid="SqlDataSource1"
        runat="server">
        
        <headertemplate>
          <table border="1">
            <tr>
              <td><b>Product ID</b></td>
              <td><b>Product Name</b></td>
            </tr>
        </headertemplate>
          
        <itemtemplate>
          <tr>
            <td> <%# Eval("ProductID") %> </td>
            <td> <%# Eval("ProductName") %> </td>
          </tr>
        </itemtemplate>
          
        <footertemplate>
          </table>
        </footertemplate>
      </asp:repeater>
        
            <asp:sqldatasource id="SqlDataSource1"          
            connectionstring="<%$ ConnectionStrings:NorthWindConnection%>" 
        selectcommand="SELECT ProductID, ProductName FROM [Products] Where ProductID <= 10"
        runat="server">
      </asp:sqldatasource>
               
    </form>      
  </body>
</html>

설명

DataSourceID 속성을 사용하여 컨트롤이 ID 해당 데이터 원본을 검색하는 데 사용해야 하는 Repeater 데이터 원본 컨트롤의 속성에 액세스합니다. 속성에서 참조하는 데이터 소스 컨트롤은 인터페이스를 DataSourceID 구현하는 모든 컨트롤일 수 있습니다 IDataSource . 데이터 원본 컨트롤은 참조하는 컨트롤과 동일한 명명 컨테이너 Repeater 또는 컨트롤의 Repeater 부모 컨트롤에 있어야 합니다. 속성 값을 DataSourceID 지정하면 컨트롤이 Repeater 지정된 데이터 원본 컨트롤에 바인딩됩니다. 메서드를 명시적으로 호출 DataBind 하는 코드를 작성할 필요가 없습니다.

또는 속성을 사용하여 컨트롤에 DataSource 바인딩할 값의 원본을 Repeater 지정할 수 있습니다. 데이터 원본은 인터페이스(예: 개체) 또는 System.Collections.ArrayList 인터페이스를 System.Data.DataView 구현 System.Collections.IEnumerable 하는 IListSource 컬렉션이어야 합니다. 속성을 설정할 DataSource 때 데이터 바인딩을 수행하려면 코드를 작성해야 합니다.

값과 DataSourceID 속성 모두에 DataSource 대해 지정된 경우 ASP.NET 데이터 원본 System.Web.HttpException 을 확인할 수 없으며 예외가 throw됩니다.

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

적용 대상

추가 정보