DataBind rows x to y to an ASP.NET repeater

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi All,

Is there a way that I can bind a certain range of rows in
a DataSet to an ASP.NET repeater? I want to add paging
to the repeater, so only want to display 10 rows of the
dataset on each page.

I did manage to do this by creating a DataView of the
DataSet and deleting all rows that I do not want to show,
but this does not seem the ideal way to do it.

Each row has 14 columns, one of which is an ID but will
not be in an order that I can filter on.

Thanks for any ideas,
Steve
 
Hi Steve,

if you don't want to switch pages using Clientside scripting you should try
to restrict the rows while reading from the database.

But if you decided on caching the DataSet and you want 14 rows from a
particular table then just create an DataRow[] with 14 rows and use an
indexer in the DataRowCollection of the DataTable to get the rows from. So
something like (untested)

DataRowCollection rows = dataTable.Rows;
int numberOfRowsToShow = Math.Min(14, rows.Count-startRowIndex-1);
DataRow[] dataSource = new DataRow[numberOfRowsToShow];
for (int i=0;i<numberOfRowsToShow;i++)
dataSource = rows[i+startRowIndex];

and use the dataSource as the DataSource for the repeater.

Robert
 
I found the solution to my problem, use a PagedDataSet
which has the functionality built in.

Steve
 
Back
Top