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;
namespace SampleCS
{
public class 고급페이징테스트 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected int intPage = 0;//고급2 : 몇번째 페이지를 보여줄건지
private void Page_Load(object sender, System.EventArgs e){
if(!Page.IsPostBack){
this.DataGrid1.VirtualItemCount = 10000;//고급1
ReadData();
}
}
private void ReadData(){
SqlConnection objCon = new SqlConnection(
"server=(local);database=Sample;uid=Sample;pwd=Sample");
objCon.Open();SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText =
"Select Top 10 Num From PagingTest Where Num Not In (Select Top " + intPage*10 + " Num From PagingTest Order By Num Desc) Order By Num Desc";//고급3
objCmd.CommandType = CommandType.Text;
SqlDataAdapter objDa = new SqlDataAdapter();
objDa.SelectCommand = objCmd;
DataSet objDs = new DataSet();
objDa.Fill(objDs, "PagingTest");
this.DataGrid1.DataSource = objDs;this.DataGrid1.DataBind();
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
intPage = e.NewPageIndex;//고급4
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
ReadData();
}
}
}