protected void Page_Load(object sender, EventArgs e)
{
//1 dimensional Array::::
string[] array = { "Anil","Kumar","Anilkumar","Eresh","Archana" };
Grid1D.DataSource = array;
Grid1D.DataBind();
//2 Dimensional array::::
string[,] arra1 ={
{ "John", "21" },
{ "Smith", "33" },
{ "Ryder", "15" },
{ "Jake", "18"},
{ "Tom","34" }
};
ArrayList arraylist = new ArrayList();
for (int i = 0; i < 5; i++)
{
arraylist.Add(new ListItem(arra1 [i, 0], arra1 [i, 1]));
}
Grid2D.DataSource = arraylist;
Grid2D.DataBind();
//Multi Dimensional Array:::::
string[,] Multiarray = {
{ "John", "21", "Berlin", "Germany" },
{ "Smith", "33" ,"London", "UK"},
{ "Ryder", "15" ,"Sydney", "Australia"},
{ "Jake", "18", "Tokyo", "Japan"},
{ "Tom","34" , "Mumbai", "India"}
};
DataTable dt = new DataTable();
dt.Columns.Add("Name", Type.GetType("System.String"));
dt.Columns.Add("Age", Type.GetType("System.String"));
dt.Columns.Add("City", Type.GetType("System.String"));
dt.Columns.Add("Country", Type.GetType("System.String"));
for (int i = 0; i < 5; i++)
{
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["Name"] = Multiarray[i, 0];
dt.Rows[dt.Rows.Count - 1]["Age"] = Multiarray[i, 1];
dt.Rows[dt.Rows.Count - 1]["City"] = Multiarray[i, 2];
dt.Rows[dt.Rows.Count - 1]["Country"] = Multiarray[i, 3];
}
GridMultiD.DataSource = dt;
GridMultiD.DataBind();
String[] data = { "test-1", "test-2", "test-3", "test-4", "test-5" };
GridViewTest.DataSource = from d in data
select new { myColumn = d };
GridViewTest.DataBind();
}
Friend Understand This Code in proper way and Execute in your Application.