16 Temmuz 2015 Perşembe

C# DataTable sıralama

            DataTable dt = new DataTable("TestTable");
            dt.Columns.Add("Kolon1");
            dt.Columns.Add("Kolon2");

            dt.Rows.Add(1, "deneme 1");
            dt.Rows.Add(7, "deneme 7");
            dt.Rows.Add(3, "deneme 3");
            dt.Rows.Add(5, "deneme 5");
            dt.Rows.Add(2, "deneme 2");

 

            DataView dataView = dt.DefaultView;
            dataView.Sort = "Kolon1";
            DataTable dtSortedAsc = dataView.ToTable();
 


            dataView.Sort = "Kolon1 desc";
            DataTable dtSortedDesc = dataView.ToTable();

Hiç yorum yok :

Yorum Gönder