dinesh
dinesh

Reputation: 3

Is it possible to put temporary data into datagridview without any datasource

I want to put my data into data grid view, by manually adding columns in it, so how can i do that,please help me.

Thank You in Advance.

Upvotes: 0

Views: 1054

Answers (2)

Conrad Lotz
Conrad Lotz

Reputation: 8828

Try the following that might solve your problem:

Ensure that the gridview(assuming he ID="gridview1") is in the markup and that AutoGenerateColumns="True"

DataTable dataTable = new dataTable();
dataTable.Columns.Add("Column1");
dataTable.Columns.Add("Column2");
dataTable.Columns.Add("Column3");

DataRow dataRow = dataTable.NewRow();

dataRow["Column1"] = "";
dataRow["Column2"] = "";
dataRow["Column3"] = "";

dataTable.Rows.Add(dataRow);

gridview1.DataSource = datatable;
gridview1.DataBind();

Upvotes: 2

Joe Ratzer
Joe Ratzer

Reputation: 18569

What about something like:

var grd = new GridView();
grd.AutoGenerateColumns = false;
BoundField field = new BoundField();
field.DataField = "CustomerName";
field.HeaderText = Resources.GlobalResources.Customer;
DataControlField col = field;
grd.Columns.Add(col);
grd.DataSource = sortedCustomers;
grd.DataBind();

Upvotes: 0

Related Questions