Please refer this code
C# Code
Namespaces
using System.Data;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Item"), new DataColumn("Price"), new DataColumn("Total") });
dt.Rows.Add("Shirt", 200, 0);
dt.Rows.Add("Football", 30, 0);
dt.Rows.Add("Bat", 22.5, 0);
dt.Rows.Add("Ring", 25, 0);
dt.Rows.Add("Band", 77, 0);
dt.Rows.Add("Glass", 57, 0);
//This will create the DataTable definition
//Data will not be copied just DataTable definition
DataTable dt3 = dt.Clone();
for (int i = 0; i <=2; i++)
{
DataRow dr = dt.Rows[i];
dt3.ImportRow(dr);
}
}
}
VB Code
Namespace
Imports System.Data
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("Item"), New DataColumn("Price"), New DataColumn("Total")})
dt.Rows.Add("Shirt", 200, 0)
dt.Rows.Add("Football", 30, 0)
dt.Rows.Add("Bat", 22.5, 0)
dt.Rows.Add("Ring", 25, 0)
dt.Rows.Add("Band", 77, 0)
dt.Rows.Add("Glass", 57, 0)
'This will create the DataTable definition
'Data will not be copied just DataTable definition
Dim dt3 As DataTable = dt.Clone()
For i As Integer = 0 To 2
Dim dr As DataRow = dt.Rows(i)
dt3.ImportRow(dr)
Next
End If
End Sub