日期:2014-05-17  浏览次数:20481 次

【处女贴】求救:实现搜索后,分页该如何重新绑定?

void bind() ----返回所有数据;

void GoSearch() --- 实现搜索;

首次载入页面,是返回 bind();

这个是上一页的代码,返回的是bind();

C# code

    protected void lnkbtnPre_Click(object sender, EventArgs e)
    {
        if (this.TeacherInfoList.PageIndex > 0)
        {
            this.TeacherInfoList.PageIndex = this.TeacherInfoList.PageIndex - 1;
            bind();
        }
    }



现在出现的问题是:上一页下一页的数据总是返回 bind()的,搜索后也是。

我想改成按了搜索按钮(GoSearch)后,分页数据就变成搜索结果后的,该怎么改?

貌似很简单,但是又不知道加哪里。

初学.NET,望大虾们不吝赐教,不甚感激!

------解决方案--------------------
protected void lnkbtnSearch_Click(object sender, EventArgs e)
{
this.TeacherInfoList.PageIndex = 0;
GoSearch();
}
------解决方案--------------------
C# code
protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.AspNetPager1.PageSize = Const.PageSize;
                this.BindConsumer();
            }
        }
private void BindConsumer()
        {
            string[] keys = new string[] { "CRID", "IsDetail" };
            Dictionary<string, object> dictionary = this.GetQueryDictionary();
            if (dictionary != null)
            {
                int recordCount;
                DataSet ds = (new ZYIOT.CR.BLL.Consumer.V_CR_ConsumerForUser()).GetPageList(this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex - 1, null, out recordCount, dictionary);
                this.AspNetPager1.RecordCount = recordCount;

                if (recordCount > 0)
                {
                    Method.BindGridView(this.GridView1, keys, ds.Tables[0].DefaultView);

                    return;
                }
            }

            this.AspNetPager1.RecordCount = 0;
            Method.BindGridView(this.GridView1, keys, null);
        }
/// <summary>
        /// 生成查询字典
        /// </summary>
        /// <returns></returns>
        private Dictionary<string, object> GetQueryDictionary()
        {
            Dictionary<string, object> dictionary = new Dictionary<string, object>();

            DateTime dt;
            //开始日期范围
            if (!string.IsNullOrEmpty(this.txtBuyTimeStartQuery.Text.Trim()))
            {
                if (DateTime.TryParse(this.txtBuyTimeStartQuery.Text.Trim(), out dt))
                {
                    dictionary.Add("BuyTimeStart", dt.Date);
                }
                else
                {
                    this.ReSetStartDate();
                    dictionary.Add("BuyTimeStart", System.DateTime.Now.Date.AddDays(1 - System.DateTime.Now.Day));
                }
            }
 return dictionary;
        }