Please check this code
private DataTable CreateDataTable()
{
DataTable myDataTable = new DataTable();
DataColumn myDataColumn;
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "ItemName";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "ItemRate";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "ItemQty";
myDataTable.Columns.Add(myDataColumn);
AddDataToTable("ItemName1", "ItemRate1", "ItemQty1", myDataTable);
gvItems.DataSource = myDataTable;
gvItems.DataBind();
return myDataTable;
}
private void AddDataToTable(string strItemName, string strItemRate, string strItemQty, System.Data.DataTable myTable)
{
DataRow row;
row = myTable.NewRow();
row["ItemName"] = strItemName;
row["ItemRate"] = strItemRate;
row["ItemQty"] = strItemQty;
myTable.Rows.Add(row);
}
Hope this works :)