Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Databinding to multi-dimensional arrays

Total Hit ( 1751)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Someone asked whether it was possible to data bind to a multi-dimensional array, and if so how. Below is a simple example that demonstrates how to do so, it is not a super inspired scenario but you get the idea. Note that in addition to handling arrays, the concept can be applied to any hierarchical or nested data structure

Click here to copy the following block
<html>

  <script language="C#" runat=server>
    void Page_Load(Object sender, EventArgs e) {
      // Create and populate a multi-dimensional array
      int [][] MyArray = new int[5][];
      for (int i=0; i<5; i++) {
        MyArray[i] = new int[6];
        for (int x=0; x<6; x++) {
          MyArray[i][x] = x+(6*i);
        }
      }
      // Databind array to server controls
      Outer.DataSource = MyArray;
      Outer.DataBind();
    }
  </script>

<body>

  <asp:datalist id="Outer" runat=server>
  <template name="ItemTemplate">
    Here is an array's values:
    <asp:repeater datasource="<%#Container.DataItem%>" runat=server>
      <template name="ItemTemplate">
        <%# Container.DataItem %>
      </template>
    </asp:repeater>
  </template>
  </asp:datalist>

</body>
</html>


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.