Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在asp网格中的表格顶部添加新行_C#_Asp.net - Fatal编程技术网

C# 如何在asp网格中的表格顶部添加新行

C# 如何在asp网格中的表格顶部添加新行,c#,asp.net,C#,Asp.net,我在这里向dataTable添加一个新行。有没有办法将新行添加到表的顶部而不是底部 DataTable dtCurrentTable = (DataTable)Session["dsRAComponent"]; DataRow drCurrentRow; drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["MODELNO"] = String.Empty; drCurrentRow["MODELDESC"] = String.Empty;

我在这里向dataTable添加一个新行。有没有办法将新行添加到表的顶部而不是底部

DataTable dtCurrentTable = (DataTable)Session["dsRAComponent"];
DataRow drCurrentRow;
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["MODELNO"] = String.Empty;
drCurrentRow["MODELDESC"] = String.Empty;
drCurrentRow["QTY"] = 0;
dtCurrentTable.Rows.Add(drCurrentRow);

Session["dsRAComponent"] = dtCurrentTable;
//Rebind the Grid with the current data
gvReceivedComponent.DataSource = dtCurrentTable;
gvReceivedComponent.DataBind();

你可以试试这个:

dtCurrentTable.Rows.InsertAt(drCurrentRow, 0);