Ramesh Durai
Ramesh Durai

Reputation: 2686

DataTable - Sorting the results according to a value in column

Below is my DataTable values.

Cards   Signals
card1   DO
card1   DO
card2   DO
card2   DO
card2   DO
card3   DO

I want my DataTable which has the value "card2" at the top. How we can achieve this?

Upvotes: 0

Views: 125

Answers (1)

vikas
vikas

Reputation: 2830

Suppose dtMy is your current table, and you will get your sorted result in dt

DataTable dt = new DataTable();
        dt = new DataView(dtMy, "Cards= 'card2'", "", DataViewRowState.CurrentRows).ToTable();
        dt.Merge(new DataView(dtMy, "Cards<> 'card2'", "", DataViewRowState.CurrentRows).ToTable());

Upvotes: 2

Related Questions