Hôm nay vào lúc 3h5phút chiều tại công ty có động đất. Lần đầu tiên biết được cảm giác đó. Mọi thứ đều run lên, cảm giác sợ đến. CŨng may là chỉ là địa chấn nhỏ thôi, không sao hết.
Trong asp.net thì có rất nhiều cách để phân trang như: sử dụng paging trong Datagrid, hay sử dụng các câu lệnh SQL như cursor hay dùng bảng tạm... Nhưng đây là một cách khác. Sử dụng method Fill của DataAdapter để thêm vào DataSet các row theo index (chỉ mục). Source code: WebForm1.aspx
<table cellspacing="0" cellpadding="0" border="0" style="BORDER-RIGHT: red 1px solid; BORDER-TOP: red 1px solid; BORDER-LEFT: red 1px solid; BORDER-BOTTOM: red 1px solid">
<tr>
<td style="BORDER-RIGHT: red 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: red; BORDER-BOTTOM: red 1px solid">
WebForm1.aspx.cs: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; /******************************************************************** created: 2005/11/01 created: 1:11:2005 14:51 filename: WebForm1.aspx.cs
#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click); this.LinkButton2.Click += new System.EventHandler(this.LinkButton2_Click); this.Load += new System.EventHandler(this.Page_Load);
} #endregion
private void LinkButton1_Click(object sender, System.EventArgs e) { int index = int.Parse(Label1.Text); index-=int.Parse(TextBox2.Text); index=index<0?0:index; Label1.Text= index.ToString(); Build_List(); }
private void LinkButton2_Click(object sender, System.EventArgs e) { int index = int.Parse(Label1.Text); index+=int.Parse(TextBox2.Text); Label1.Text= index.ToString(); Build_List();