我在我的网站上使用 RadGrid 控件,并为 radgrid 启用分页,并在 sql profiler 上监视它的活动,我知道 radgrid 为每个分页获取数据,然后显示当前页面的数据。
DataSet obj_Dataset = new DataSet(); // is global
这是我写的代码Page_Load
:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection obj_SqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConection"].ToString());
SqlCommand obj_sqlCommand = new SqlCommand();
obj_sqlCommand.CommandText = "select ProductID,ProductName,CategoryID from products";
obj_sqlCommand.CommandType = CommandType.Text;
obj_sqlCommand.Connection = obj_SqlConnection;
SqlDataAdapter obj_DataAdapter = new SqlDataAdapter(obj_sqlCommand);
obj_SqlConnection.Open();
obj_DataAdapter.Fill(obj_Dataset, "Products");
obj_DataAdapter.Dispose();
obj_sqlCommand.Dispose();
obj_SqlConnection.Close();
}
这是我的代码RadGrid1_NeedDataSource
:
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = obj_Dataset.Tables["Products"];
}
我正在使用 ASP.net 2010 和 Sqlserver 2008。