/// <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();
}