
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<HTML>
	<HEAD>
		<title>使用DataView对数据进行排序和检索示例</title>
	
		<script language=C# runat=server>
		
			void Page_Load(object sender, System.EventArgs e)
			{
				string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];
				string Sql = "SELECT CustomerID, CompanyName, Country FROM Customers";

				SqlConnection thisConnection = new SqlConnection(ConnectionString);
				SqlDataAdapter adapter = new SqlDataAdapter(Sql, thisConnection);

				// 创建DataTable对象
				DataTable table = new DataTable();

				// 填充数据到DataTable
				adapter.Fill(table);

				// 创建DataView，并在构造函数中得到排序和检索条件等参数
				DataView dataView = new DataView(table, "Country='USA'", "CompanyName DESC", DataViewRowState.CurrentRows);

				// 数据绑定
				myDataGrid.DataSource = dataView;
				myDataGrid.DataBind();
			}		
		
		</script>
	
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<h3>使用DataView对数据进行排序和检索示例</h3>
			<asp:DataGrid id="myDataGrid" runat="server"></asp:DataGrid>
		</form>
	</body>
</HTML>
