Skip to content

Instantly share code, notes, and snippets.

@corespider
Created February 26, 2022 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corespider/c0c8f762be4799d2520dd38b0d7f7762 to your computer and use it in GitHub Desktop.
Save corespider/c0c8f762be4799d2520dd38b0d7f7762 to your computer and use it in GitHub Desktop.
How to Bind Array to GridView in ASP.Net
//Multi Dimensional Array
string[,] arrMultiD = {
{ "Ram","Delhi", "India" },
{ "John", "WS DC","USA" },
{ "Stewart","London", "UK" },
{ "Sham","Mumbai", "India"},
{ "Tod","Florida","USA" },
{ "Bryan","Kitet","Russia" }
};
DataTable dt = new DataTable();
dt.Columns.Add("Name", 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 < 6; i++)
{
dt.Rows.Add();
dt.Rows[dt.Rows.Count - 1]["Name"] = arrMultiD[i, 0];
dt.Rows[dt.Rows.Count - 1]["City"] = arrMultiD[i, 1];
dt.Rows[dt.Rows.Count - 1]["Country"] = arrMultiD[i, 2];
}
gridView3.DataSource = dt;
gridView3.DataBind();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment