這個問題似乎很常見,我已經通過這個answer。使用SqlDataAdapter來頁面SqlDataReader源
不幸的是,我的頁面仍未被分頁。這裏是我的代碼在C#中的樣子:
SqlCommand command = new SqlCommand("(SELECT ......", Connection);
SqlDataAdapter myAdapter = new SqlDataAdapter(command);
DataTable dt = new DataTable();
myAdapter.Fill(dt);
command.Connection = connection;
command.Connection.Open();
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.AllowPaging = true;
GridView1.PageSize = 15;
command.Connection.Close();
command.Connection.Dispose();
不幸的是,當我這樣做時,我的分頁不出現。難道我做錯了什麼?
感謝
您是否在選擇時獲得了15條記錄?另外,在Databind()方法被調用之前,設置所有Paging相關的屬性。 –
哇,那很簡單。我只需在數據綁定()之前設置它。謝謝! – Kevin
哦,OnPageIndexChanging和OnPageIndexChanged有什麼區別? – Kevin