/// <summary>
/// DataTable中使用Order By排序与Where过滤
/// </summary>
private void Bind()
{
//这里构造一个数据源
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(System.String));
dt.Columns.Add("uName", typeof(System.String));
dt.Columns.Add("uDate", typeof(System.DateTime));
for (int i = 0; i < 10; i++)
{
DataRow dr = dt.NewRow();
dr["ID"] = i.ToString();
dr["uName"] = "name" + i;
dt.Rows.Add(dr);
}
dt.DefaultView.Sort = "ID asc";//相当于Order By
dt.DefaultView.RowFilter = "ID>5";//相当于Where
GridView1.DataSource = dt;
GridView1.DataBind();
}