I think you can be a bit more clever than copying the rows into another table; I would try creating a small helper class that implements IEnumerable and wraps a DataView; just off the top of my head, here something that might get you started:
MyDataList.Data Source = new Show5(MyView);
public class Show5 : IEnumerable
{
DataView m_view;
public Show5(DataView v)
{
m_view = v;
}
public IEnumerator GetEnumerator()
{
return new E5(m_view.GetEn umerator());
}
internal class E5 : IEnumerator {
private IEnumerator m_e;
private int m_cnt = 0;
internal E5(IEnumerator e) {
m_e = e;
}
public object Current {
get { return m_e.Current; }
}
public bool MoveNext() {
if (m_cnt > 5) return false;
m_cnt++;
return m_e.MoveNext();
}
public void Reset() {
m_e.Reset();
m_cnt = 0;
}
}
}
"Greg Hurlman" <ghurlman*AT*sq uaretwo*DOT*net > wrote in message news:33******** *************** ***********@mic rosoft.com...
To do this, you'll want to use the DataTable's DefaultView to set any sorting
or filtering you have, and then create a new DataTable, clone the old
datatable, and then import the first 5 rows from the original DataTable's
dataview, like this:
Dim OriginalView As DataView = OriginalTable.D efaultView
OriginalView.Ro wFilter = "Whatever"
OriginalView.So rt = "Whatever"
Dim NewTable As DataTable = OriginalTable.C lone()
For i As Integer = 1 To 5
NewTable.Import Row(OriginalVie w(i).Row)
Next
MyDataGrid.Data Source = NewTable
MyDataGrid.Data Bind()
"wh1974" wrote:
I have a DataTable that I'm binding to a DataList control on my web page. I
want to be able to restrict the number of rows that are initially displayed
from the DataTable. For example I want to be able to show the first 5 rows,
a button will then allow the user to 'show all records'.
Although I've used a DataView before, I am unsure how this can be of use
when I need to restrict the number of rows. I am aware of the RowFilter
property, but this only allows me to specify a SQL like filter.
Thanks,
Wayne.