Created
February 26, 2022 12:05
-
-
Save corespider/c0c8f762be4799d2520dd38b0d7f7762 to your computer and use it in GitHub Desktop.
How to Bind Array to GridView in ASP.Net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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