Extracted online, verified:
Create a able, add column names to the table datatable, Add rows to the table datatable, and filter the contents of the table datatable.
1. Create a able
Datatable dt = new datable (); // you can create a name for the table, TB
2. Add a column name to the table:
DT. Columns. Add ("ID", typeof (system. int32); // The type can be changed, such as system. int32, system. Double ..
DT. Columns. Add ("type", typeof (system. String ));
3. Add rows to the table. content:
Datarow ROW = DT. newrow ();
Row ["ID"] = 1;
Row ["type"] = "123 ";
DT. Rows. Add (ROW); // you can add
Row = DT. newrow ();
Row ["ID"] = 2;
Row ["type"] = "456 ";
DT. Rows. Add (ROW );
4. filter the table content and find the information with ID 1.
Datarow [] arr = DT. Select ("ID = 1"); // an array is returned.
5. Insert the filtered content into another table
Datatable dtnew = DT. Clone (); // copy the column information in the table DT to dtnew, instead of copying data.
Foreach (datarow row in ARR)
{
Dtnew. Rows. Add (ROW); // Add the filtered information to dtnew.
}
DT. acceptchanges (); // refresh the page after adding it!
6. Sort the table
DT. defaultview. Sort = "id DESC ";
7. delete data
DT. Rows. Remove (ROW); // delete a row based on the row information.
DT. Rows. removeat (INDEX); // delete an index
8. Modify DT column information
Row2 [0]. beginedit ();
Row2 [0] ["status"] = 0;
Row2 [0]. endedit ();