Which control should I use when binding a multidimensional array

Platform: ASP.NET| Category: DataList

Use a DataList as follows.

.aspx


<asp:datalist id='DataList1' runat='server'>
<ItemTemplate>
	<asp:repeater datasource='<%#Container.DataItem%>' runat=server ID='Repeater1' >
	<ItemTemplate>
			<%# Container.DataItem %>
	</ItemTemplate>
	</asp:repeater>
</ItemTemplate>
</asp:datalist>

VB.NET


Private Sub Page_Load(sender As Object, e As System.EventArgs)
   	’ Put user code to initialize the page here
  	 ’ Create and populate a multi-dimensional array
   	Dim MyArray(4) As Integer()
	Dim i As Integer
	For i = 0 To 3
	      MyArray(i) = New Integer(5) {}
	      Dim x As Integer
		For x = 0 To 4
		         MyArray(i)(x) = x + 5 * i
		Next 
	Next 
	DataList1.DataSource = MyArray
	DataList1.DataBind()
End Sub ’Page_Load

C#


private void Page_Load(object sender, System.EventArgs e)
{
	// Put user code to initialize the page here
	// Create and populate a multi-dimensional array
	int [][] MyArray = new int[4][];
	for (int i=0; i<4; i++) 
	{
		MyArray[i] = new int[5];
		for (int x=0; x<5; x++) 
		{
			MyArray[i][x] = x+(5*i);
		}
	}
	DataList1.DataSource = MyArray;
	DataList1.DataBind();
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.