The two-dimensional array can be converted to datatalbe.
The following is a program instance, where converttoable able can be called directly, as long as you set different parameter types according to the array type.
Protected void page_load (Object sender, eventargs E)
{
String [,] arr = new string [2, 3];
Arr [0, 0] = "1 ";
Arr [0, 1] = "2 ";
Arr [0, 2] = "22 ";
Arr [1, 0] = "3 ";
Arr [1, 1] = "4 ";
Arr [1, 2] = "2 ";
This. gridview1.datasource = converttodatatable (ARR );
Gridview1.databind ();
}
Private datatable converttodatatable (string [,] ARR)
{
Datatable datasouce = new datatable ();
For (INT I = 0; I <arr. getlength (1); I ++)
{
Datacolumn newcolumn = new datacolumn (I. tostring (), arr [0, 0]. GetType ());
Datasouce. Columns. Add (newcolumn );
}
For (INT I = 0; I <arr. getlength (0); I ++)
{
Datarow newrow = datasouce. newrow ();
For (Int J = 0; j <arr. getlength (1); j ++)
{
Newrow [J. tostring ()] = arr [I, j];
}
Datasouce. Rows. Add (newrow );
}
Return datasouce;
}