Tuesday, November 22, 2011

GridView: dynamic column binding

I try to bind columns to a GridView  dynamically and the code is shown below:

DataTable table = new DataTable();

//add column
table.Columns.Add(new DataColumn("name", typeof(string)));

//add row
DataRow row = table.NewRow();
row["Name"] = "abc";
table.Rows.Add(row);

//bind data to gridView
GridView1.DataSource = table;
GridView1.DataBind();

No comments:

Post a Comment