Working with Asp.net GridView without DataBinding

一世执手 提交于 2019-12-24 15:04:58

问题


Is it possible to populate asp.net GridView with data and operate on those data without dataBinding, as it is possible with Winforms DataGridView?


回答1:


You can set the data source to a datatable that you can build up in code with whatever you like.

 var table = new DataTable();
 table.Columns.Add("Column1");
 table.Columns.Add("Column2");

var row = table.NewRow();
row["Column1"] = "test";
row["Column2"] = "test2";

table.Rows.Add(row);

GridView.DataSource = table;
GridView.DataBind();

You can also set a gridview's data source with a list:

var yourList = new List<YourRowStuff>();

get the list from a database query or build it up manually in code....

GridView.DataSource = yourList;
GridView.DataBind();


来源:https://stackoverflow.com/questions/1853461/working-with-asp-net-gridview-without-databinding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!