Maxer 's Blog
态度决定一切,理想成就未来!

Object Tag Syntax: <object runat="server" />

Object tags enable page developers to declare and create instances of variables using a declarative, tag-based syntax. The following example demonstrates how the object tag can be used to create an instance of an ArrayList class.

<object id="items" class="System.Collections.ArrayList" runat="server"/>

The object will be created automatically at run time and can then be accessed through the ID "items".

<html>

   <script language="C#" runat=server>

      void Page_Load(Object sender, EventArgs e) {

         ArrayItems.Add("One");
         ArrayItems.Add("Two");
         ArrayItems.Add("Three");

         MyList.DataSource = ArrayItems;
         MyList.DataBind();
      }

   </script>

   <body>
   
   <object id="ArrayItems" class="System.Collections.ArrayList" runat=server/>

      <asp:datalist id="MyList" runat=server>

         <ItemTemplate>

            Here is a value: <%# Container.DataItem %>

         </ItemTemplate>

      </asp:datalist>

   </body>

</html>
posted on 2006-03-27 17:20  Maxer`s Blog  阅读(288)  评论(0编辑  收藏  举报