???? ???? ??? ??? ?????? ASP.NET

?????? ????????? ?????? ?????????
???? ???????: 307860 - ??? ???????? ???? ????? ????? ??? ???????.
???? ??? ??????? ??? Microsoft.NET ??????? ????? ?????? ???? ?????? ???????:
  • System.Data
  • System.Data.SqlClient
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ????? ??? ?????? ASP.NET ?????.

?????? ??? ????? ???? ASP.NET ??????? ???? ?? ??? ????? ????? ????? Microsoft:
305140 ????? ?????? ASP.NET

??????? ????

?? ??? ?????? ASP.NET? ????? ??? ?? ???? ???? ???? ?????? ????? ?? ??????? ?? ????????? ?? ??????. ??? ??????? ??? ????????? ???? ????? ???? ??? ??????? ???????? ?? ????? ?????? ?? ????? ????.

????? ??? ??????? ????? ??? ???????? ??????? ????????:

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

< % # %> ???? ??????

???? ASP.NET ??? ???? ?????? ???????? ??????? < % # % >. ??? ???? ?????? ?? ?????? ???????? ??? ???????? ?? ????.aspx. ???? ??? ???????? ??? ????? ????????? ???? ??? ??????. ??????? ??????? ????? ????? ?? ??? ?????? ????? ?? ????? ??????:
  • ??????? ??????? (???? ?????? ???? ???????):
    <%# custID %>
    					
  • ?????? (???? ?????? ????):
    <asp:ListBox id="List1" datasource='<%# myArray %>' runat="server">
    					
  • ??????? (???? ?????? ???? ?????):
    <%# ( customer.First Name + " " + customer.LastName ) %>
    					
  • ????? ????? (???? ?????? ?????? ???????):
    <%# GetBalance(custID) %>
    					
?? ??????? ???????? ?????? < % # %> ???????? ??????? ??? ???? ????????? ?? ???? ?????? ???? ?????? ?? ????.aspx. ?????? ?????? ?????? ??? ?????? ???? ???? ???? ??? TextBox :
<asp:textbox id=txt text="<%# custID %>" runat=server />
				
?????? ??? ???? ?? ????????? ??? ???? ?????? ???? ????????? ????.NET ??????? ???? ????? ?????? ????? ????? ????? (SDK):
???? ???? ????? ??? ????????
.aspx http://msdn2.microsoft.com/en-us/library/bda9bbfx (vs.71)

Page.DataBind() ????? Control.DataBind()

??? ????? ????? ???????? ????? ?????? ???????? ???????? ?? ????.aspx? ??? ??? ???????? ???? ???????? ?????. ????? ??????? ??????? Control.DataBind ?? Page.DataBind ???? ???????? ??? ????? ????????.

?????? ?????? ????? ????? ???????. ???????? ??????? ?? ??? ??? ???? ????? ???????? ????? ???? ?????? ??? Page.DataBind ??? ??????? ???????. ??? ????? ??? ?????? ??? ???? ?????? ??? ???? ??????? ??? ??????? DataBind ???? ???? ???? ????? ?? ??? ???? ???????? ???? ???? ????? Page.DataBind ????? ??????. ???? ???? ??? ??????? Page.DataBind (?? DataBind) ?? ??? Page_Load .

????? ?? ????????? ??? ????? DataBind ? ???? ????? SDK ???? ???.NET ???????: ????? Control.DataBind
http://msdn.microsoft.com/en-us/library/w5e5992d.aspx

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

???? ????? ???? ??????? ??? ????? ???? ???? ????? ???? ???? ???? ??? ???????. ????? ??????? ????? ?????? ??? ???? ???? ?? ???????? ?? ????? ?????? ??????. ???? ???? ????? ???? ??????? ???? ???????? ?????? DataMember ? ???? ?????? ????? ??? ???????.

??? ????? ?????? ??? ????? ???? ???????? ?????? ??? ??? ?? ?????? ???? ???? IEnumerable?? ICollection????? ??????????? .

???? ?????? repeater

???? ?????? Repeater ????? ???????? ??? ????????. ???? ?????? Repeater "?????"? ?? ??? ??? ???? ?? ???? ??????? ?? ???????. ????? ??? ?? ????? ????? ???? ????? HTML? ???????? ???? ???????? ?? ????? ???? ??????.

?? ??? ??? ????? ????????? ???????? ????? ??????? ???? ???? ????? ????? ???? ?????? Repeater ? ???? ????????:

??????: ??? ????? ?????? ????? ??????? ? ???????? ?????? ?????? ??.

Visual Basic.NET
<%@ Page Language="vb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)

   Dim cnn As SqlConnection = New SqlConnection("server=(local);" & _
                                                "database=pubs;Integrated Security=SSPI")
   Dim cmd As SqlDataAdapter = New SqlDataAdapter("select * from authors", cnn)
   Dim ds As DataSet = New DataSet()
   cmd.Fill(ds)
   Repeater1.DataSource = ds
   Repeater1.DataBind()

End Sub
</script>
<html>
<body>
   <form id="Form1" method="post" runat="server">
      <asp:Repeater id="Repeater1" runat="server">
         <ItemTemplate>
         <%# DataBinder.Eval(Container.DataItem,"au_id") %><br>
	 </ItemTemplate>
      </asp:Repeater>
   </form>
</body>
</html>
				
Visual C#.NET
<%@ Page language="c#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
void Page_Load(Object sender, EventArgs e) 
{ 
   SqlConnection cnn = new 
       SqlConnection("server=(local);database=pubs;Integrated Security=SSPI"); 
   SqlDataAdapter da = new SqlDataAdapter("select * from authors", cnn); 
   DataSet ds = new DataSet(); 
   da.Fill(ds, "authors"); 
   Repeater1.DataSource = ds.Tables["authors"];
   Repeater1.DataBind();
}
</script>
<html>
<body>
   <form id="WebForm2" method="post" runat="server">
      <asp:Repeater id="Repeater1" runat="server">
         <ItemTemplate>
         <%# DataBinder.Eval(Container.DataItem,"au_id") %><br>
    	 </ItemTemplate>
      </asp:Repeater>
   </form>
</body>
</html>
				
Visual J#.NET
<%@ Page language="VJ#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

 <script runat="server">
void Page_Load(Object sender, EventArgs e) 
{ 
    SqlConnection cnn = new SqlConnection("server=(local);database=pubs;Integrated
         Security=SSPI"); 
    SqlDataAdapter da = new SqlDataAdapter("select * from authors", cnn); 
    DataSet ds = new DataSet(); 
    da.Fill(ds, "authors"); 
    DataTableCollection dtc = ds.get_Tables();
    int index = dtc.IndexOf("authors");
    Repeater1.set_DataSource(dtc.get_Item(index));
    Repeater1.DataBind();
}
</script>
<html>
<body>
   <form id="WebForm2" method="post" runat="server">
      <asp:Repeater id="Repeater1" runat="server">
         <ItemTemplate>
         <%# DataBinder.Eval(Container.DataItem,"au_id") %><br>
             </ItemTemplate>
      </asp:Repeater>
   </form>
</body>
</html>
				
????? ?? ????????? ??? ???? ?????? Repeater ? ???? ????? SDK ???? ???.NET ???????:
???? ???? ???? ????? repeater
http://msdn.microsoft.com/en-us/library/x8f2zez5.aspx

???? ??????

??? ????? ???????? ????? ?????? ??????? ???????? ??? ????????. ????? ?????? ??? ????? ??????? ?????? ???? ?????? ???. ???? ???? ?????? Repeater ? DataList ????? ??? ??????? ????? ?? ???? ???? ??????? ?? ???? HTML ?? ??? ???????.

????? ?? ????????? ??? ???? ??????? ???? ????? SDK ???? ???.NET ???????:
???? ???? ???? ????? dataList
.aspx http://msdn.microsoft.com/en-us/library/9cx2f3ks (VS.85)

???? ???? DataGrid

???? ?????? DataGrid ???? ????? ???????? ????? ???????? ??? ????????. ??? ????? ????? ????? ?????? ?? DataGrid? ????? ????? ??? ?????? ??? "???????" ???????? ????? ??????. ???? ????? ???? ?????? DataGrid ??? ???????? ??? ???? ???? ?????? ??? ?????? ??????????? ????????. DataGrid ???? ???? ??????? ???????? ??????? ???????? ?????? ??? ?????? ???????? ????.

????? ?? ????????? ??? ???? ?????? DataGrid ? ???? ????? SDK ???? ???.NET ???????:
???? ???? ???? ????? Datalist
.aspx http://msdn.microsoft.com/en-us/library/aa710742 (VS.71)

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

??? ??? ????? ????? ?????? ??? ???????? ?? ????? ?????? ? ??? ???????? ??? ????? ???? ???????. ????? ??????? DataSet ?? ????? DataReader ?????? ??? ?????? ?? ????? ??????.

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

?????? ???????? ????? ??? ????? ???????? ????? ????????? ??? ?? ??? ?????? ???????? ??? ???????? ?????? ????????? ????. ???? DataSet ???????? ??????? ?????? ?? ??? ?? ????????? ?? ????? ?????? ??? ??? ??? ????? ??????? (XML). ???? ?????? ???????? ???? ??????; ??? ????? ????? ????? ??? ?????? ?? ?????? ??? ?????? ??? ??? ????? ????? ??????. ?? ??? ??????? ?????? ???? ????? ??????? ?????? ???????? ???? ???????? ??? ???? ????:

??????: ??? ????? ?????? ????? ??????? ? ???????? ?????? ?????? ??.

Visual Basic.NET
Dim cnn As SqlConnection = New SqlConnection("server=(local);" & _
                                             "database=pubs;Integrated Security=SSPI")
Dim cmd As SqlDataAdapter = New SqlDataAdapter("select * from authors", cnn)
Dim ds As DataSet = New DataSet()
cmd.Fill(ds)
MyRepeater.DataSource = ds
MyRepeater.DataBind() 
				
Visual C#.NET
SqlConnection cnn = new SqlConnection("server=(local);
                                       database=pubs;Integrated Security=SSPI"); 
SqlDataAdapter da = new SqlDataAdapter("select * from authors", cnn); 
DataSet ds = new DataSet(); 
da.Fill(ds);
MyRepeater.DataSource = ds;
MyRepeater.DataBind(); 
				
Visual J#.NET
SqlConnection cnn = new SqlConnection("server=(local);
                                       database=pubs;Integrated Security=SSPI"); 
SqlDataAdapter da = new SqlDataAdapter("select * from authors", cnn); 
DataSet ds = new DataSet(); 
da.Fill(ds); 
MyRepeater.set_DataSource(ds);
MyRepeater.DataBind();
				
????? ?? ????????? ??? ??? ?????? ???????? ? ???? ????? SDK ???? ???.NET ???????:
??? ?????? ????????
.aspx http://msdn2.microsoft.com/en-us/library/system.data.dataset (vs.71)

??? DataReader

???? ?????? ??? ??? ????? ??? ???? ???????? (??? ?????) ???? ?????? ?? ???? ??? DataReader ?? ????. ??? ???? ??????? ?? ?????? ??????? ?????? DataReaderDropDownList ??? DataReader ???? ?????? ???. ???? ???????? ???????? ??????? ????? ??????? ??? SqlDataReader ???? ???????? ??? ???? ????:

Visual Basic.NET
Dim cnn As SqlConnection = New SqlConnection("server=(local);" & _
                                             "database=pubs;Integrated Security=SSPI")
Dim cmd As SqlCommand = New SqlCommand("select * from authors", cnn)

cnn.Open()
MyRepeater.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
MyRepeater.DataBind()
				
Visual C#.NET
SqlConnection cnn = new SqlConnection("server=(local);
                                       database=pubs;Integrated Security=SSPI");
SqlCommand cmd = new SqlCommand("select * from authors", cnn);

cnn.Open();
MyRepeater.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection);
MyRepeater.DataBind();
				
Visual J#.NET
SqlConnection cnn = new SqlConnection("server=(local);
                                       database=pubs;Integrated Security=SSPI"); 

SqlCommand cmd = new SqlCommand("select * from authors", cnn); 

cnn.Open();
MyRepeater.set_DataSource(cmd.ExecuteReader(CommandBehavior.CloseConnection));
MyRepeater.DataBind();
				
?????? ??? ???? ?? ????????? ??? ?????? ????? ????????? SqlDataReader ?? ASP.NET? ???? ???????? ??????? ?? ?????.NET Framework SDK:
??? SqlDataReader
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx

????? ??????? ASP.NET ??? ?????? ??????
.aspx http://msdn2.microsoft.com/en-us/library/5dws599a (vs.71)

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

????? ??????? ????? ?? ????? ????? ???? ????? ???? ????? ??????? ??????? ?? ???? ??????. ????? ??? ????? ????? ??? ?????? ????.

????? DataBinder.Eval

????? ???? ???? ???????? ?? ???????? ???? ??? ??????? ?? ????? ??????? ?? ????? ???? ???????? ??? ????? ?????? ?? ?????????. ????? ?????? ??? ?????? ??????? DataBinder.Eval ????? ?????? ????????. ?? ????? ????????? ???????? ??????? "au_id" ??? ????? ????? ?? ???? ???????? ????? ?????:
<%# DataBinder.Eval(Container.DataItem,"au_id") %>
				
????? ?? ????????? ??? ????? DataBinder.Eval ? ???? ????? SDK ???? ???.NET ???????:
????? DataBinder.Eval
http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx

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

??? ??? ????? ???? ?? ??????? ?????? ??????? ???????. ????? ??????? ?????? ???? ?????? ????? ???. ???? ??? ??????? ???????? ??????? ???? ???? ?????? ??????? ????????? ???????? ???????. ????? ??? ????? ???? ?????? ?? ?????? ???? ??????. ??????? ????? ???????? ???????? ??????? ??????? ???????:

Visual Basic.NET
' DataTable as the DataSource
<%# CType(Container.DataItem, System.Data.DataRowView)("au_id") %>

' DataReader as the DataSource
<%# CType(Container.DataItem, System.Data.Common.DbDataRecord)("au_id") %>

' DataReader as the DataSource
<%# CType(Container.DataItem, System.Data.Common.DbDataRecord)(0) %>
				
Visual C#.NET
// DataTable as the DataSource
<%# ((System.Data.DataRowView)Container.DataItem)["au_id"] %> 

// DataReader as the DataSource
<%# ((System.Data.Common.DbDataRecord)Container.DataItem)["au_id"] %>

// DataReader as the DataSource
<%# ((System.Data.Common.DbDataRecord)Container.DataItem)[0] %>
				
Visual J#.NET
// DataTable as the DataSource
<%# ((System.Data.DataRowView)Container.DataItem)["au_id"] %> 

// DataReader as the DataSource
<%# ((System.Data.Common.DbDataRecord)Container.DataItem)["au_id"] %>

// DataReader as the DataSource
<%# ((System.Data.Common.DbDataRecord)Container.DataItem)[0] %>
				
???? ?? ?????? ????? ??????? ??? DataTable? ??????? ????? ?? ?????????? DataReader ????? ??????.

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

????? ???? ??????? ????? ????????????? ????? ?????? ???? ????????. ???? ??? ????? ??? ???? ?????? ????? ??? ???? ??????. ????? ????????? ???????? ?????? HTML ?????? ???? ???? ????? ????? ?? ItemTemplate:
<asp:repeater id=rptr runat=server>
   <itemtemplate>
      <asp:label id=lblAuthorID runat=server />
   </itemtemplate>
</asp:repeater>
				
???????? ??????? ?????? ?? ?????? ?????? ??:

Visual Basic.NET
public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
  
   'TODO: Retrieve data from a database,
   'and bind the data to a list control.

End Sub

public Sub rptr_OnItemDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptr.ItemDataBound
   Dim rec As DataRowView
   rec = e.Item.DataItem

   'Make sure that you have the data.
   If Not IsDBNull(rec) Then
      Dim l1 As Label
      l1 = e.Item.FindControl("lblAuthorID")
      l1.Text = rec("au_id").ToString()
   End If
End Sub
				
Visual C#.NET
public void Page_Init(object sender, System.EventArgs e)
{
   rptr.ItemDataBound += new RepeaterItemEventHandler(rptr_OnItemDataBound);
}
public void Page_Load(object sender, System.EventArgs e)
{
   // TODO: Retrieve data from a database,
   // and bind the data to a list control.
}
public void rptr_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
   System.Data.Common.DbDataRecord rec = (System.Data.Common.DbDataRecord)
                                          e.Item.DataItem;
   if(rec!=null) //Make sure that you have the data.
   {
      Label l1 = (Label)e.Item.FindControl("lblAuthorID");
      l1.Text = rec["au_id"].ToString();
   }
}
				
Visual J#.NET
public void Page_Init(Object sender, System.EventArgs e)
{
            rptr.add_ItemDataBound(new RepeaterItemEventHandler(rptr_OnItemDataBound));
}
private void Page_Load(Object sender, System.EventArgs e)
{
            // TODO: Retrieve data from a database,
            // and bind the data to a list control.
}
public void rptr_OnItemDataBound(Object sender, RepeaterItemEventArgs e)
{
            System.Data.Common.DbDataRecord rec = (System.Data.Common.DbDataRecord)
                                                   e.get_Item().get_DataItem();
            if (rec != null) //Make sure that you have the data.
            {
                        Label l1 = (Label)e.get_Item().FindControl("lblAuthorID");
                        l1.set_Text(((rec.get_Item("au_id")).ToString()));
            }
}
				

???????

???? ???????: 307860 - ????? ??? ??????: 17/????? ??????/1434 - ??????: 3.0
????? ???
  • Microsoft ASP.NET 1.0
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual J# .NET 2003 Standard Edition
  • Microsoft ASP.NET 1.1
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
????? ??????: 
kbarttyperoadmap kbdatabinding kbinfo kbservercontrols kbmt KB307860 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????307860

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

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com