Stewie Griffin
Stewie Griffin

Reputation: 9327

gridview does not bind datatable copy in C#

I am trying to bind a copy of datatable to the gridview, but it does not display it. Here is a sample code:

var cloneData = originalData.clone();
gvTable.DataSource = cloneData;
gvTable.Databind();

if I bind originalData instead of cloneData, it works.. what's wrong with the copy?

asp.net C#.

Upvotes: 0

Views: 478

Answers (2)

hungryMind
hungryMind

Reputation: 7009

See difference between clone and copy.

Upvotes: 1

Nick Heidke
Nick Heidke

Reputation: 2847

You need to use Copy() instead of Clone()

Both the Copy and the Clone methods create a new DataTable with the same structure as the original DataTable. The new DataTable created by the Copy method has the same set of DataRows as the original table, but the new DataTable created by the Clone method does not contain any DataRows.

Source

Upvotes: 2

Related Questions