When we use datatable.newrow command, a new empty row added to bottom of rows. However I want newrow to added to top of datatable. How can I make it?
Asked
Active
Viewed 7.6k times
3 Answers
82
You use the NewRow to create a row with the same columns. To actually get it into the DataTable, you've got to do
myDataTable.Rows.InsertAt(myDataRow, 0);
Where 0 is the index you want to insert it at.

Nick DeVore
- 9,748
- 3
- 39
- 41
-
5myDataTable.Rows.InsertAt(myDataRow,0); is the correct form. Thanks – mavera Dec 03 '08 at 16:50
25
Here is the best example to add row in table
DataRow newRow = myDataTable.NewRow();
newRow[0] = "0";
newRow[1] = "Select one";
myDataTable.Rows.InsertAt(newRow, 0);
It's set the row on first

Sunil Acharya
- 1,153
- 5
- 22
- 39
3
This One is Wrong
myDataTable.Rows.InsertAt(0,myDataRow);
Please use the below line instead of that
myDataTable.Rows.InsertAt(myDataRow,0);
-
4I have written correct form as a comment of accepted answer. You can see it above. – mavera Jul 26 '10 at 05:34