user366312
user366312

Reputation: 17026

Working with Asp.net GridView without DataBinding

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

Upvotes: 1

Views: 2961

Answers (1)

Kevin LaBranche
Kevin LaBranche

Reputation: 21098

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();

Upvotes: 2

Related Questions