求大侠帮忙
各位大侠,本人初学.net不久,有个问题求助。
如何把下面这段代码改为GridView用存储过程获取数据的?
DataSet ds;
SqlDataAdapter dr;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlConnection con = new SqlConnection(strconn);
con.Open();
com = new SqlCommand();
com.Connection = con;
com.CommandText = "select count(*) from Student";
AspNetPager1.AlwaysShow = true;
AspNetPager1.PageSize = 2;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
con.Close();
DataBind();
}
}
protected void DataBind()
{
string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
dr = new SqlDataAdapter("select * from Student", strconn);
ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "Student");
this.GridView1.DataSource = ds.Tables["Student"];
this.GridView1.DataBind();
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
DataBind();
}