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 Answer
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();
5 Comments
user366312
Isn't this databinding? this.GridView1.DataSource = ((DataTable)Session["myDatatable"]).DefaultView; this.GridView1.DataBind();
user366312
This is also databinding. Me.GridView1.DataSource = userinfos Me.GridView1.DataBind()
Kevin LaBranche
All unbound means to me is that the grid is not operating against a DB for me (insert, update, delete,etc).. I control that not the grid. In the above scenario's I control the grid which is the same in the winforms world to me....
user3750325
links have broke
Kevin LaBranche
@user7733611 Updated answer without links. :-)