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.DataSource = 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.GetEnumerator());
}
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*squaretwo*DOT*net> wrote in message news:33AA753D-4E09-4950-8519-...
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.DefaultView
OriginalView.RowFilter = "Whatever"
OriginalView.Sort = "Whatever"
Dim NewTable As DataTable = OriginalTable.Clone()
For i As Integer = 1 To 5
NewTable.ImportRow(OriginalView(i).Row)
Next
MyDataGrid.DataSource = NewTable
MyDataGrid.DataBind()
"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.
>
>
>
|