Adding new row to datatable's top

mavera picture mavera · Dec 3, 2008 · Viewed 66.2k times · Source

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?

Answer

Nick DeVore picture Nick DeVore · Dec 3, 2008

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.