在asp.net上看到这个方法,觉得挺实用的,遂把它摘录下来 private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { BindData(); } } public void BindData() { SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM Categories" ,myConnection); DataSet ds = new DataSet(); ad.Fill(ds,"Categories"); OuterGrid.DataSource = ds; OuterGrid.DataBind(); } protected DataView GetDataSource(Int32 catID) { string query = "SELECT * FROM Categories"; SqlDataAdapter ad = new SqlDataAdapter(query,myConnection); DataSet ds = new DataSet(); ad.Fill(ds,"Categories"); DataView _orders = ds.Tables["Categories"].DefaultView; _orders.RowFilter = "CategoryID='" + catID + "'"; return _orders; } 相关文章: