0

1つのasp.netデータテーブルがあり、2つのasp.netデータリストにデータバインドしたいので、データテーブルのを2つのデータテーブルにスライスします。

4

2 に答える 2

2

LINQ拡張メソッドを使用して、使用するTakeアイテムの数を指定します。

そして、Skip必要に応じてジャンプします。

var half = myList.Take(myList.Count / 2);
于 2012-11-15T11:21:27.050 に答える
0

行ごとにスライスする場合は、元のデータテーブルのコピーを作成し、適切な中間点を見つけて、行をコピーにインポートし、元のデータから削除するだけです。

次のようなものが機能するはずです。

DataTable originalTable = new DataTable();
//Load the data into your original table or wherever you get your original table from

DataTable otherTable = originalTable.Copy(); //Copys the table structure only - no data

int rowCount = originalTable.Rows.Count;
int wayPoint = rowCount / 2; //NB integer division rounds down towards 0

for(int i = 0; i <= wayPoint; i++)
{
    otherTable.ImportRow(originalTable.Rows[i]); //Imports (copies) the row from the original table to the new one
    originalTable.Rows[i].Delete(); //Marks row for deletion
}

originalTable.AcceptChanges(); //Removes the rows we marked for deletion
于 2012-11-15T11:47:11.860 に答える