How to: Get Top n Rows of DataView in C# asp.net
DataView in asp.net doesn't have any method of returning Top n rows or it doesn't accept any row filter string such as, dataview.RowFilter = "top 100". So to server the purpose you can use the method below to get top n rows from DataView. private DataView GetTopDataViewRows(DataView dv, Int32 n) { DataTable dt = dv.Table.Clone(); for (int i = 0; i { if (i>= dv.Count) { break; } dt.ImportRow(dv[i].Row); } return new DataView(dt, dv.RowFilter, dv.Sort, dv.RowStateFilter); }