Suppose you have 50
rows in DataTable named dt and you want to show only first 10 rows in the
GridView then call the function SelectTopRows passing first parameter as your
datatable object dt and second parameter as 10.This function will return first
10 rows from the datatable.Now you can bind that filtered datatable i.e. dtnew
to your gridview.
public DataTable
SelectTopRows(DataTable dt, int count)
{
DataTable
dtnew = dt.Clone();
for (int i = 0; i
< count; i++)
{
dtnew.ImportRow(dt.Rows[i]);
}
return dtnew ;
}
VB.Net Code to get specified number of records from datatable in Asp.net
Public Function
SelectTopRows(dt As DataTable, count As Integer) As DataTable
Dim dtnew As DataTable = dt.Clone()
For i As Integer = 0 To count - 1
dtnew .ImportRow(dt.Rows(i))
Next
Return dtnew
End Function
0 comments:
Post a Comment