using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using UcfarDB;

//演示地址：http://UcfarPager20.51aspx.com
public partial class _Default : System.Web.UI.Page 
{
    DBHelper db = new DBHelper();
    Pager pager = new Pager();
    public string sql;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            
            InitData(1);

    }

    private void InitData(int pageindex)
    {
        //int pageCount;//绑定方法一
        //int itemCount;//绑定方法一
        string hanzi = this.TextBox1.Text.Trim().ToString();
        if (hanzi != "")
        {
            sql = "select * from DicData WHERE HANZI = '" + hanzi + "'  ";
          this.UcfarPager1.RecordCount = pager.CreateCountSQL(sql);//绑定方法二
        }
        else
        {
            sql = "select * from DicData ";
            this.UcfarPager1.RecordCount = pager.CreateCountSQL(sql);//绑定方法二
        }

       //Pager.OrderByStruct order = new Pager.OrderByStruct("hanzi", Pager.Directions.ASC);//绑定方法一
       //DataTable ds = pager.GetData_SQL2005(sql, pageindex, UcfarPager1.PageSize, out pageCount, out itemCount, order);//绑定方法一
       //this.UcfarPager1.RecordCount = itemCount;//绑定方法一
       //this.GridView1.DataSource = ds;//绑定方法一
        DataTable dt = db.ExecuteDataSet(sql, UcfarPager1.PageSize * (pageindex-1), UcfarPager1.PageSize).Tables[0];
        this.GridView1.DataSource = dt;//绑定方法二
        GridView1.DataBind();
        
    }

    protected void UcfarPager1_PageChanged(object sender, EventArgs e)
    {
        InitData(UcfarPager1.CurrentPageIndex);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        InitData(1);
    }
}
