Create new rows in a DataGrid control using the DataGridItem object ASP NET

New DataGridItem(itemIndex, dataSetIndex, itemType)
The itemIndex is the index of the item in the DataGrid control and the dataSetIndex is the index number of the bound data source item that appears in the DataGrid. When adding new rows, these values arent relevant and you can use 0 for both of them. The itemType argument is important because it identifies the type of DataGridItem object you want. Valid values include: Item, Header, and Footer to name a few. Following is an example of how youll create a new DataGridItem header:
Dim dgItem As DataGridItem
dgItem = New DataGridItem(0, 0, ListItemType.Header)
This line of code creates a DataGrid Header in whichever style youve defined for DataGrid headers. Next, you need to add data to the DataGridItem object. You do this by adding new cells to the DataGridItem object. The next set of code creates two columns and adds them to the header:
Dim dgCell As TableCell
dgCell = New TableCell
dgCell.Text = "Title"
dgItem.Cells.Add(dgCell)
dgCell = New TableCell
dgCell.Text = "Author"
dgItem.Cells.Add(dgCell)
All thats left to do is add the DataGridItem object to the DataGrid rows collection. For this task you have the Add or AddAt methods of the controls collection. The Add method adds the row to the end of the collection and AddAt adds the row to an existing location in the collection. The following line of code adds the new header to the end of a DataGrid named DataGrid1:
DataGrid1.Controls(0).Controls.Add(dgItem)