???? ID: 306154 - ????? ???????: 04 ?????? 2010 - ??????: 2.0

??????? Repeater ???????? ?? ????? C# .NET ?? ????? ?? ???? ?? ?????????? ????????? ???? ???? ????

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ???? ????? ?? ?? ???? ?? ????? ???? ?? ??? ???????Repeater???????? ?????????? ???? ????????? ???? ?? ??? ??? ?? ???? ????-????? ?? ???????? ???? ?? ??? ?? concept ???? ?? ???? ????


?????? ?????? ?? ??? ?????

  1. Microsoft Visual Studio .NET ???? ????..
  2. ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????.
  3. ????? ????,????? C# ??????????? ???????????????? ???????? ????-????? ????, ?? ???? ???ASP.NET ??? ??????????? ???????????????.
  4. ??????????????? ???, WebApplication ?????#, ?? ??? ???? ????NestedRepeater. ??? ?? ??????? ????? ?? ????? ????, ????? ??? ?? ??? ??? ???? ???HTTP://localhost. ????? ?? ??? ????? ???? ????????????:
    HTTP://localhost/ NestedRepeater
    ????? ????,OK.
  5. ????????? Explorer, ????-????? ????NestedRepeater????????? ??? ???, ?? ??? ?????add?? ????-????? ????, ?? ???? ?????? ??????? ?????.
  6. ??? ??????? ?? ??? ?? ??? ?????NestedRepeater, ?? ????? ?????????.
  7. ??? ??? ??????? ?? ???? ??? It opens in Design View in the Integrated Development Environment (IDE) of Microsoft Visual Studio .NET. From the Toolbox, select theRepeatercontrol, and then drag it to the Web Form page.
  8. ????????? ????IDproperty of thisRepeater???? ?? ??? ????????parentRepeater.
  9. Switch to the HTML view for this Web Form. ??? ???? ?? ???, ????? ????htmltab in the lower-left corner of the Designer. TheRepeatercontrol generates the following HTML code:
    <asp:Repeater id="parentRepeater" runat="server"></asp:Repeater>
    					
  10. ??? ????? ??? ??????Repeatertags:
    <itemtemplate>
         <b><%# DataBinder.Eval(Container.DataItem, "au_id") %></b><br>
    </itemtemplate>
    					
    After you do that, the HTML code for theRepeater??????????? ??:
    <asp:Repeater id="parentRepeater" runat="server">
    	<itemtemplate>
    	     <b><%# DataBinder.Eval(Container.DataItem, "au_id") %></b><br>	
          </itemtemplate>
    </asp:Repeater>
    					
  11. ?????? Explorer ???, ???? ?????NestedRepeater.aspx?? ????-????? ????, ?? ???? ???????? ???to switch to the NestedRepeater.aspx.cs code-behind file.
  12. Add the following namespace declaration to the top of the file:
    using System.Data;
    using System.Data.SqlClient;
    					
  13. ????? ??? ??????Page_Loadevent to create a connection to thePubs???????, ?? ??? ????? ???? ?? ????????????? ?? ??? ??????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. ????????? Explorer, 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???? ?? ??? ????????ItemTemplate?????? ?? ???Repeater???????? ???
  2. ??? ???????? ??????????? ?? ??? ???Repeater?? ??? ??? ????????? ????:
    <asp:repeater ... datasource='<%# ((DataRowView)Container.DataItem)
          .Row.GetChildRows("myrelation") %>' >
    					
    ??? ???? ?? ??????? ??????????? ?? ??? ???Repeater????????, ????? ?? ??? HTML ???Repeater???????? (?????? ?? ??????) ?? ??? ??? ????? ???? ??:
    <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. ????? ????? directive ????? ?? ???? ??? ??? ??????:
    <%@ Import Namespace="System.Data" %>
    					
  4. Behind-??? ??? ??? ????? ?????? ??? ?????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"]);
    
    					
    ?? ????? ???????????? ?? ??? ??????DataSet, ?? ???? ??? ?????? ?? ?????? ?????? ?? ??? ????? ?????? ???
  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/default.asp?URL=/Library/en-us/cpguide/HTML/cpconaddingrelationshipbetweentwotables.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaddingrelationshipbetweentwotables.asp)

?????? ?? ??? ???? ????? ????????
HTTP://MSDN.Microsoft.com/Library/default.asp?URL=/Library/en-us/cpguide/HTML/cpconnavigatingrelationshipbetweentwotables.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconnavigatingrelationshipbetweentwotables.asp)

Repeater ??? ????? ????????
HTTP://MSDN.Microsoft.com/Library/default.asp?URL=/Library/en-us/cpgenref/HTML/cpconrepeaterwebservercontrol.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconrepeaterwebservercontrol.asp)

???? ???? ???? ??:
  • 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 kbmt KB306154 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:306154  (http://support.microsoft.com/kb/306154/en-us/ )