Siva CCSPL
Siva CCSPL

Reputation: 105

How to bind DataTable to DataGridView as a DataSource

I have a DataTable and I insert a Row using DataColumnCollection, and then bind to the DataSource. Afterwards, I saw in the grid's first column System.Data.DataColumnCollection that the value is not present. Give me an idea.

Upvotes: 1

Views: 142

Answers (1)

KV Prajapati
KV Prajapati

Reputation: 94653

Try it,

DataTable dt=new DataTable();
dt.Columns.Add("No",typeof(int)); // Adding column into ColumnsCollection
dt.Columns.Add("Name");

dt.Rows.Add(1,"AAA");  // Adding rows into RowsCollection
dt.Rows.Add(2,"BBB");

DataGridView1.DataSource=dt; // Binding datasource

Upvotes: 1

Related Questions