protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
public int zong = 0;
public int current = 0;
protected System.Web.UI.WebControls.Literal Literal1;
public int size=0;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
zong=this.getCount();
if(!Page.IsPostBack)
{
string temp = "";
try
{
temp = Convert.ToString(Request["page"]);
}
catch
{
}
current = temp==null||temp.Length<1?(0):(Convert.ToInt32(temp));
BindData(current);
}
}
public void BindData(int current)
{
///Esdata
///data200503
int qian = 10*current;
string sql = string.Format("select top 10 [id],company,tel from data200503 where [id] not in(select top {0} [id] from data200503 order by [id]) order by [id]",qian);
SqlConnection conn = new SqlConnection();
conn.ConnectionString="initial catalog=ESdata;data source=.;user id=sa;password=";
SqlCommand cmd = new SqlCommand();
cmd.Connection=conn;
cmd.CommandText=sql;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand=cmd;
DataSet ds = new DataSet();
da.Fill(ds);
this.DataGrid1.DataSource=ds.Tables[0].DefaultView;
this.DataGrid1.DataBind();
int pagecount =zong%10==0?(zong/10):(zong/10+1);
StringBuilder pager = new StringBuilder();
for(int i=0;i<100;i++)
{
string br = (i+1)%50==0?("<br>"):("");
pager.Append(" <a href='tews3.aspx?page="+i+"'>"+(i+1).ToString()+"</a>").Append(br);
}
this.Literal1.Text=pager.ToString();
//this.DataGrid1.PageCount=zong%10==0?(zong/10):(zong/10+1);
}
public int getCount()
{
int iii = 0;
string sql = string.Format("select count(*) from data200503");
SqlConnection conn = new SqlConnection();
conn.ConnectionString="initial catalog=ESdata;data source=.;user id=sa;password=";
SqlCommand cmd = new SqlCommand();
cmd.Connection=conn;
cmd.CommandText=sql;
conn.Open();
iii = Convert.ToInt32(cmd.ExecuteScalar());
conn.Close();
return iii;
}