aa.aspx
用DataGrid控件進行分頁
<form id="form1" runat="server">
<div>
<br />
<asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="true" PageSize="2" OnPageIndexChanged="GridView1_PageIndexChanging"
>
<ItemStyle Font-Size="Small"/>
<HeaderStyle Font-Size="Small" BorderColor="#C0C0FF" BackColor="#99CCCC"/>
<PagerStyle PrevPageText="[上一頁]" NextPageText="[下一頁]" Font-Size="Small" />
</asp:DataGrid><br />
</div>
</form>
aa.aspx.cs
用DataGrid控件進行分頁 - 513394217 - ㄨiao愛
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class aa : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = null;
conn = new SqlConnection();
conn.ConnectionString = "server=PC-4355211\\SQLEXPRESS;Initial Catalog=BookShop;"
+ "User ID=qq;Password=qqpassword";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from Books";
cmd.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet data = new DataSet();
da.Fill(data, "BookShop");
DataGrid1.DataSource = data;
DataGrid1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
this.DataGrid1.DataBind();
}
}