DataSet中的表DataTable的页面显示不直接由DataTable提供,而是由DataView提供,DataTable不支持数据的筛选,而DataView可以。
下面看个小例子:
//默认显示
void ViewData(DataTable dt)
{
DataView dv = new DataView(dt);
//或者DataView dv=dt.DataView();
this.DataList1.DataSource = dv;
this.DataList1.DataBind();
}
//倒序显示
void ViewData_Sort(DataTable dt)
{
DataView dv = new DataView();
dv.Table = dt;
dv.Sort = "UserID DESC";
this.DataList1.DataSource = dv;
this.DataList1.DataBind();
}
//字符长度筛选控制显示
void ViewData_Len(DataTable dt)
{
DataView dv = new DataView();
dv.Table = dt;
dv.RowFilter = "Len(title)>4";
this.DataList1.DataSource = dv;
this.DataList1.DataBind();
}
//字符类似筛选控制显示
void ViewData_Like(DataTable dt)
{
DataView dv = new DataView();
dv.Table = dt;
dv.RowFilter = "Address like '%北京%'";
this.DataList1.DataSource = dv;
this.DataList1.DataBind();
}
//多个筛选控制显示
void ViewData_More_Like(DataTable dt)
{
DataView dv = new DataView();
dv.Table = dt;
dv.RowFilter = "Address like '%北京%'";
this.DataList1.DataSource = dv;
this.DataList1.DataBind();
}