Below is the sample code snippet that will do your work. You have to make sure where are you adding the control and also need to add event handler to peroform operation like RowDataBound, Edit, delete etc based on your requirments.
GridView gridView = new GridView();
gridView.ID = "gridViewDynamic";
gridView.DataSource = mydatasource;