Adding new row to datatable's top

♀尐吖头ヾ 提交于 2019-12-03 14:25:45

问题


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?


回答1:


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.




回答2:


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




回答3:


This One is Wrong

myDataTable.Rows.InsertAt(0,myDataRow); 

Please use the below line instead of that

myDataTable.Rows.InsertAt(myDataRow,0);


来源:https://stackoverflow.com/questions/337797/adding-new-row-to-datatables-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!