Datagrid 的手动分页不影响速度

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("&nbsp;&nbsp;<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;
  } 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值