You can try something like below. But be aware that the outcome could be different depending on the way the data being sorted in the
datatable
. Or you can make the datasource to return row_number as suggested by other member and then filter by that variable.
void Test()
{
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
table.Rows.Add(22, "xx", "dd", DateTime.Now);
table.Rows.Add(777, "Dilantin 2", "cc", DateTime.Now);
var resultRange = table.AsEnumerable()
.Where((row, index) => index >= 2 && 5 >= index)
.CopyToDataTable();
var value = "di";
var result = resultRange.Select("Drug like '%" + value + "%'");
}
c# - How to select rows from DataTable based on Index / Row Number? - Stack Overflow[
^]
https://www.dotnetperls.com/datatable[
^]