±â¼ú ÀÚ·á: 306154 - ¸¶Áö¸· °ËÅä: 2006³â 5¿ù 22ÀÏ ¿ù¿äÀÏ - ¼öÁ¤: 4.6

ÁßøµÈ Repeater ÄÁÆ®·Ñ°ú Visual C# .NETÀ» »ç¿ëÇÏ¿© °èÃþ µ¥ÀÌÅ͸¦ Ç¥½ÃÇÏ´Â ¹æ¹ý

½Ã½ºÅÛ ÆÁº» ¹®¼­ÀÇ ³»¿ëÀº ±ÍÇϰ¡ »ç¿ëÇÏ´Â ¿î¿µ üÁ¦¿Í ´Ù¸¥ ¿î¿µ üÁ¦¿¡ ÇØ´çÇÕ´Ï´Ù. ¹®¼­ ³»¿ë Áß ±ÍÇÏ¿Í °ü·Ã ¾ø´Â ºÎºÐÀº Ç¥½ÃµÇÁö ¾Ê½À´Ï´Ù.
ÀÌ ¹®¼­´Â ÀÌÀü¿¡ ´ÙÀ½ ID·Î ÃâÆÇµÇ¾úÀ½: KR306154

ÀÌ ÆäÀÌÁö¿¡¼­

¸ðµÎ È®´ë | ¸ðµÎ Ãà¼Ò

¿ä¾à

ÀÌ ¹®¼­¿¡¼­´Â ÁßøµÈ Repeater ÄÁÆ®·ÑÀ» »ç¿ëÇÏ¿© °èÃþ µ¥ÀÌÅ͸¦ Ç¥½ÃÇÏ´Â ¹æ¹ýÀ» ¼³¸íÇÕ´Ï´Ù. ÀÌ °³³äÀº ´Ù¸¥ ¸ñ·Ï ¹Ù¿îµå ÄÁÆ®·Ñ¿¡ Àû¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.


ºÎ¸ð Å×ÀÌºí¿¡ ¹ÙÀεù

  1. Microsoft Visual Studio .NETÀ» ½ÃÀÛÇÕ´Ï´Ù.
  2. ÆÄÀÏ ¸Þ´º¿¡¼­ »õ·Î ¸¸µé±â¸¦ °¡¸®Å² ´ÙÀ½ ÇÁ·ÎÁ§Æ®¸¦ ´©¸¨´Ï´Ù.
  3. ÇÁ·ÎÁ§Æ® Çü½Ä¿¡¼­ Visual C# ÇÁ·ÎÁ§Æ®¸¦ ´©¸¥ ´ÙÀ½ ÅÛÇø´¿¡¼­ ASP.NET À¥ ÀÀ¿ë ÇÁ·Î±×·¥À» ´©¸¨´Ï´Ù.
  4. À§Ä¡ »óÀÚ¿¡¼­ WebApplication#¸¦ »èÁ¦ÇÑ ´ÙÀ½ NestedRepeater¸¦ ÀÔ·ÂÇÕ´Ï´Ù. ·ÎÄà ¼­¹ö¸¦ »ç¿ëÇϸé http://localhost¶ó´Â ¼­¹ö À̸§À» ±×´ë·Î »ç¿ëÇÕ´Ï´Ù. ´ÙÀ½ °æ·Î°¡ À§Ä¡ »óÀÚ¿¡ ³ªÅ¸³³´Ï´Ù.
    http://localhost/ NestedRepeater
    È®ÀÎÀ» ´©¸¨´Ï´Ù.
  5. ¼Ö·ç¼Ç Ž»ö±â¿¡¼­ NestedRepeater ÇÁ·ÎÁ§Æ® À̸§ ³ëµå¸¦ ¸¶¿ì½º ¿À¸¥ÂÊ ´ÜÃß·Î ´©¸£°í Ãß°¡¸¦ °¡¸®Å² ´ÙÀ½ Web Form Ãß°¡¸¦ ´©¸¨´Ï´Ù.
  6. Web FormÀÇ À̸§À» ÁöÁ¤ÇÏ·Á¸é NestedRepeater¸¦ ÀÔ·ÂÇÏ°í ¿­±â¸¦ ´©¸¨´Ï´Ù.
  7. »õ Web FormÀÌ ¸¸µé¾îÁý´Ï´Ù. »õ Web FormÀº Microsoft Visual Studio .NET IDE(ÅëÇÕ °³¹ß ȯ°æ)ÀÇ µðÀÚÀÎ º¸±â¿¡¼­ ¿­¸³´Ï´Ù. µµ±¸ ¸ðÀ½¿¡¼­ Repeater ÄÁÆ®·ÑÀ» ¼±ÅÃÇÑ ´ÙÀ½ Web Form ÆäÀÌÁö·Î ²ü´Ï´Ù.
  8. ÀÌ Repeater ÄÁÆ®·ÑÀÇ ID ¼Ó¼ºÀ» parentRepeater·Î º¯°æÇÕ´Ï´Ù.
  9. ÀÌ Web FormÀÇ HTML º¸±â·Î ÀüȯÇÕ´Ï´Ù. ÀÌ·¸°Ô ÇÏ·Á¸é µðÀÚÀ̳ÊÀÇ ¿ÞÂÊ ¸Ç ¾Æ·¡¿¡ ÀÖ´Â HTML ÅÇÀ» ´©¸¨´Ï´Ù. Repeater ÄÁÆ®·ÑÀÌ ´ÙÀ½ HTML Äڵ带 »ý¼ºÇÕ´Ï´Ù.
    <asp:Repeater id="parentRepeater" runat="server"></asp:Repeater>
    					
  10. ´ÙÀ½ Äڵ带 Repeater ű׿¡ Ãß°¡ÇÕ´Ï´Ù.
    <itemtemplate>
         <b><%# DataBinder.Eval(Container.DataItem, "au_id") %></b><br>
    </itemtemplate>
    					
    ÀÌ·¸°Ô ÇÑ ÈÄ RepeaterÀÇ HTML ÄÚµå´Â ´ÙÀ½°ú °°½À´Ï´Ù.
    <asp:Repeater id="parentRepeater" runat="server">
    	<itemtemplate>
    	     <b><%# DataBinder.Eval(Container.DataItem, "au_id") %></b><br>	
          </itemtemplate>
    </asp:Repeater>
    					
  11. ¼Ö·ç¼Ç Ž»ö±â¿¡¼­ NestedRepeater.aspx¸¦ ¸¶¿ì½º ¿À¸¥ÂÊ ´ÜÃß·Î ´©¸¥ ´ÙÀ½ ÄÚµå º¸±â¸¦ ´­·¯ NestedRepeater.aspx.cs ÄÚµå ¼û±è ÆÄÀÏ·Î ÀüȯÇÕ´Ï´Ù.
  12. ´ÙÀ½ ³×ÀÓ½ºÆäÀ̽º ¼±¾ðÀ» ÆÄÀÏ ¸Ç À§¿¡ Ãß°¡ÇÕ´Ï´Ù.
    using System.Data;
    using System.Data.SqlClient;
    					
  13. ´ÙÀ½ Äڵ带 Page_Load À̺¥Æ®¿¡ Ãß°¡ÇÏ¿© Pubs µ¥ÀÌÅͺ£À̽º¿¡ ¿¬°áÇÑ ´ÙÀ½ Authors Å×À̺íÀ» Repeater ÄÁÆ®·Ñ¿¡ ¹ÙÀεùÇÕ´Ï´Ù.
          public void Page_Load(object sender, EventArgs e)
          {
             //Create the connection and DataAdapter for the Authors table.
             SqlConnection cnn = new SqlConnection("server=(local);database=pubs; Integrated Security=SSPI");
             SqlDataAdapter cmd1 = new SqlDataAdapter("select * from authors",cnn);
    
             //Create and fill the DataSet.
             DataSet ds = new DataSet();
             cmd1.Fill(ds,"authors");
             //Insert code in step 4 of the next section here.
             //Bind the Authors table to the parent Repeater control, and call DataBind.
             parentRepeater.DataSource = ds.Tables["authors"];
             Page.DataBind();
    
             //Close the connection.
             cnn.Close();
           }
    					
    Âü°í: »ç¿ëÀÚ È¯°æ¿¡ ¸Â°Ô µ¥ÀÌÅͺ£À̽º ¿¬°á ¹®ÀÚ¿­À» ¼öÁ¤ÇØ¾ß ÇÒ ¼ö ÀÖ½À´Ï´Ù.

  14. ÆÄÀÏÀ» ¸ðµÎ ÀúÀåÇÕ´Ï´Ù.
  15. ¼Ö·ç¼Ç Ž»ö±â¿¡¼­ NestedRepeater.aspx¸¦ ¸¶¿ì½º ¿À¸¥ÂÊ ´ÜÃß·Î ´©¸¥ ´ÙÀ½ ½ÃÀÛ ÆäÀÌÁö·Î ¼³Á¤À» ´©¸¨´Ï´Ù.
  16. ºôµå ¸Þ´º¿¡¼­ ¼Ö·ç¼Ç ºôµå¸¦ ´­·¯ ÇÁ·ÎÁ§Æ®¸¦ ÄÄÆÄÀÏÇÕ´Ï´Ù.
  17. ºê¶ó¿ìÀú¿¡¼­ .aspx ÆäÀÌÁö¸¦ °ËÅäÇÏ¿© ÆäÀÌÁö°¡ Áö±Ý±îÁö ÀÛµ¿ÇÏ´ÂÁö È®ÀÎÇÕ´Ï´Ù.

    Ãâ·ÂÀº ´ÙÀ½°ú °°ÀÌ ³ªÅ¸³ª¾ß ÇÕ´Ï´Ù.
    • 172-32-1176
    • 213-46-8915
    • 238-95-7766
    • 267-41-2394
    • ...

ÀÚ½Ä Å×ÀÌºí¿¡ ¹ÙÀεù

  1. NestedRepeater.aspx ÆäÀÌÁöÀÇ HTML º¸±â¿¡¼­ ´ÙÀ½ ÄÚµå ÁÙÀ» ã½À´Ï´Ù.
    <b><%# DataBinder.Eval(Container.DataItem, "au_id") %></b><br>
    						
    ÀÌ ÄÚµå µÚ¿¡ ´ÙÀ½ Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
    <asp:repeater id="childRepeater" runat="server">
    		<itemtemplate>
    	            <%# DataBinder.Eval(Container.DataItem, "[\"title_id\"]")%><br>
    		</itemtemplate>
    </asp:repeater>
    						
    ÀÌ »õ Äڵ忡¼­´Â µÎ ¹øÂ° Repeater ÄÁÆ®·ÑÀ» ºÎ¸ð Repeater ÄÁÆ®·ÑÀÇ ItemTemplate ¼Ó¼º¿¡ Ãß°¡ÇÕ´Ï´Ù.
  2. ÀÚ½Ä Repeater ÄÁÆ®·ÑÀÇ DataSource ¼Ó¼ºÀ» ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÕ´Ï´Ù.
    <asp:repeater ... datasource='<%# ((DataRowView)Container.DataItem)
          .Row.GetChildRows("myrelation") %>' >
    					
    ÀÚ½Ä Repeater ÄÁÆ®·ÑÀÇ DataSource ¼Ó¼ºÀ» ¼³Á¤ÇÑ ÈÄ µÎ Repeater ÄÁÆ®·Ñ(ºÎ¸ð ¹× ÀÚ½Ä)ÀÇ HTML ÄÚµå´Â ´ÙÀ½°ú °°½À´Ï´Ù.
    <asp:Repeater id="parentRepeater" runat="server">
    	<itemtemplate>
    		<b>
    		 <%# DataBinder.Eval(Container.DataItem, "au_id") %>
    		</b>
    		<br>
    		<asp:repeater id="childRepeater" runat="server" 
                        datasource='<%# ((DataRowView)Container.DataItem)
          .Row.GetChildRows("myrelation") %>' >
    			<itemtemplate>
    				<%# DataBinder.Eval(Container.DataItem, "[\"title_id\"]")%><br>	
    			</itemtemplate>
    		</asp:Repeater> 
    	</itemtemplate>
    </asp:Repeater>
    					
  3. ´ÙÀ½ ÆäÀÌÁö Áö½Ã¹®À» ÆäÀÌÁö ¸Ç À§¿¡ Ãß°¡ÇÕ´Ï´Ù.
    <%@ Import Namespace="System.Data" %>
    					
  4. ÄÚµå ¼û±è ÆäÀÌÁöÀÇ Page_Load À̺¥Æ®¿¡¼­ ´ÙÀ½ ÁÙÀ» ã½À´Ï´Ù.
    //Insert code in step 4 of the next section here.
    						
    ÀÌ Äڵ带 ´ÙÀ½ ÄÚµå·Î ¹Ù²ß´Ï´Ù.
             //Create a second DataAdapter for the Titles table.
             SqlDataAdapter cmd2 = new SqlDataAdapter("select * from titleauthor",cnn);
             cmd2.Fill(ds,"titles");
    
             //Create the relation between the Authors and Titles tables.
             ds.Relations.Add("myrelation",
             ds.Tables["authors"].Columns["au_id"],
             ds.Tables["titles"].Columns["au_id"]);
    
    					
    ÀÌ·¸°Ô Çϸé Titles Å×À̺íÀÌ DataSet¿¡ Ãß°¡µÈ ´ÙÀ½ Authors ¹× Titles Å×ÀÌºí °£ÀÇ °ü°è°¡ Ãß°¡µË´Ï´Ù.
  5. ÀÀ¿ë ÇÁ·Î±×·¥À» ÀúÀåÇϰí ÄÄÆÄÀÏÇÕ´Ï´Ù.
  6. ºê¶ó¿ìÀú¿¡¼­ ÆäÀÌÁö¸¦ °ËÅäÇÏ¿© ÆäÀÌÁö°¡ Áö±Ý±îÁö ÀÛµ¿ÇÏ´ÂÁö È®ÀÎÇÕ´Ï´Ù. Ãâ·ÂÀº ´ÙÀ½°ú °°ÀÌ ³ªÅ¸³ª¾ß ÇÕ´Ï´Ù.
    172-32-1176
    PS3333
    213-46-8915
    BU1032
    BU2075
    238-95-7766
    PC1035
    267-41-2394
    BU1111
    TC7777
    ...

Àüü ÄÚµå ¿¹Á¦

Nestedrepeater.aspx

<%@ Page language="c#" Codebehind="NestedRepeater.aspx.cs" AutoEventWireup="false" Inherits="NestedRepeater.NestedRepeater" %>
<%@ Import Namespace="System.Data" %>

<html>
<body>
<form runat=server>

<!-- start parent repeater -->
<asp:repeater id="parentRepeater" runat="server">
   <itemtemplate>
      <b><%# DataBinder.Eval(Container.DataItem,"au_id") %></b><br>

      <!-- start child repeater -->
      <asp:repeater id="childRepeater" datasource='<%# ((DataRowView)Container.DataItem)
      .Row.GetChildRows("myrelation") %>' runat="server">

         <itemtemplate>
            <%# DataBinder.Eval(Container.DataItem, "[\"title_id\"]")%><br>
         </itemtemplate>
      </asp:repeater>
      <!-- end child repeater -->

   </itemtemplate>
</asp:repeater>
<!-- end parent repeater -->

</form>
</body>
</html>
				

Nestedrepeater.aspx.cs

using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NestedRepeater
{
   public class NestedRepeater : System.Web.UI.Page
   {
      protected System.Web.UI.WebControls.Repeater parentRepeater;
      public NestedRepeater()
      {
         Page.Init += new System.EventHandler(Page_Init);
      }
      public void Page_Load(object sender, EventArgs e)
      {
         //Create the connection and DataAdapter for the Authors table.
         SqlConnection cnn = new SqlConnection("server=(local);database=pubs; Integrated Security=SSPI ;");
         SqlDataAdapter cmd1 = new SqlDataAdapter("select * from authors",cnn);

         //Create and fill the DataSet.
         DataSet ds = new DataSet();
         cmd1.Fill(ds,"authors");

         //Create a second DataAdapter for the Titles table.
         SqlDataAdapter cmd2 = new SqlDataAdapter("select * from titleauthor",cnn);
         cmd2.Fill(ds,"titles");

         //Create the relation bewtween the Authors and Titles tables.
         ds.Relations.Add("myrelation",
         ds.Tables["authors"].Columns["au_id"],
         ds.Tables["titles"].Columns["au_id"]);

         //Bind the Authors table to the parent Repeater control, and call DataBind.
         parentRepeater.DataSource = ds.Tables["authors"];
         Page.DataBind();

         //Close the connection.
         cnn.Close();
      }
      private void Page_Init(object sender, EventArgs e)
      {
         InitializeComponent();
      }
      private void InitializeComponent()
      {    
         this.Load += new System.EventHandler(this.Page_Load);
      }
   }
}
				

ÂüÁ¶

ÀÚ¼¼ÇÑ ³»¿ëÀº Microsoft .NET Framework SDK(¼ÒÇÁÆ®¿þ¾î °³¹ß ŰƮ)ÀÇ ´ÙÀ½ Ç׸ñÀ» ÂüÁ¶ÇϽʽÿÀ.
Å×ÀÌºí »çÀÌ¿¡ °ü°è Ãß°¡
http://msdn.microsoft.com/library/kor/default.asp?url=/library/kor/cpguide/html/cpconaddingrelationshipbetweentwotables.asp (http://msdn.microsoft.com/library/kor/default.asp?url=/library/kor/cpguide/html/cpconaddingrelationshipbetweentwotables.asp)

Å×ÀÌºí »çÀÌÀÇ °ü°è Ž»ö
http://msdn.microsoft.com/library/kor/default.asp?url=/library/kor/cpguide/html/cpconnavigatingrelationshipbetweentwotables.asp (http://msdn.microsoft.com/library/kor/default.asp?url=/library/kor/cpguide/html/cpconnavigatingrelationshipbetweentwotables.asp)

Repeater À¥ ¼­¹ö ÄÁÆ®·Ñ
http://msdn.microsoft.com/library/kor/default.asp?url=/library/kor/cpgenref/html/cpconrepeaterwebservercontrol.asp (http://msdn.microsoft.com/library/kor/default.asp?url=/library/kor/cpgenref/html/cpconrepeaterwebservercontrol.asp)




Microsoft Á¦Ç° °ü·Ã ±â¼ú Àü¹®°¡µé°ú ¿Â¶óÀÎÀ¸·Î Á¤º¸¸¦ ±³È¯ÇϽ÷Á¸é Microsoft ´º½º ±×·ì (http://support.microsoft.com/newsgroups/default.aspx) ¿¡ Âü¿©ÇϽñ⠹ٶø´Ï´Ù.

º» ¹®¼­ÀÇ Á¤º¸´Â ´ÙÀ½ÀÇ Á¦Ç°¿¡ Àû¿ëµË´Ï´Ù.
  • Microsoft ASP.NET 1.0
  • Microsoft ASP.NET 1.1
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
Ű¿öµå:?
kbdatabinding kbhowtomaster kbservercontrols KB306154