It is a combination of DataColumns and DataRow. Generally, we use it for data binding purpose. In this article we will learn how to design the DataTable , merge two DataTable and Bind the gridview control with merged DataTable. First of all, create the object of it then add some column in it. After define the columns you will enter data in the columns. We have already dicussed on this topic earlier. Today, we will focus on merge( ) method.
Add columns and rows in the DataTable (Copy and Paste)
DataTable datatable1 = new DataTable();
Above code define, we have two column that is, id with integer DataType and Name with string DataType. Similarly, we can design code for second DataTable. Like
DataTable datatable2 = new DataTable();
How to merge DataTable:After preparing the DataTable, you should use Merge( ) method. Like
Now, you have to bind the GridView with Merged DataTable.
GridView1.DataSource = datatable1;