日期:2014-05-18  浏览次数:20442 次

急!100分再问一个!IsPostBack翻页的问题?
我的问题是在页面上有5个控件:
一个TextBox1,
一个Button1,
一个DataList1,
两个HyperLink(上一页,下一页)
我想在文本框中输入一个搜索关键字,点按钮把结果查询到DataList1中,
另外可以翻页.

Button1_Click事件如下:
protected void Button1_Click(object sender, EventArgs e)
{
  string keyword = TextBox1.Text;
  string sql="select * from t1 where aa='"+keyword+"'";
  band(keyword); //绑定并包含有翻页  
}

band()方法如下:
private void bandd(string KeyWord)
{
  //省略部分代码
  if (!pages.IsFirstPage)
  {
  hpl_prev.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(indexpage - 1); //上一页
  }

  if (!pages.IsLastPage)
  {
  hpl_next.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(indexpage + 1); //下一页
  }

  //省略下面代码

}

运行时查询结果出来了,但点击下一页时就没有数据了!

请问怎么解决?分不够再加

------解决方案--------------------
点击翻页事件中,还要绑定DataList1才行
------解决方案--------------------
HyperLink 的代码贴出来看看,绑定datalist没
------解决方案--------------------
datalist翻页
C# code

/// <summary>
  /// DataList翻页程序
  /// </summary>
  private void DisplayBySection()
  {
   this.dlDoctor.Dispose();
   string SectionID = Request.Params.Get("SectionID");
   string strSectionID;
   if(SectionID!=null)
   {
    strSectionID = "select * from Doctors,Sections,BigSections,DoctorType "+
     "where Sections.BigSectionID = BigSections.BigSectionID and Sections.SectionID = Doctors.SectionID "+
     "and Doctors.DoctorTypeID = DoctorType.DoctorTypeID and DoctorType.DoctorTypeName='祖传医师'"+
     "and Doctors.SectionID = '"+SectionID+"'";
   }
   else
   { 
    strSectionID = "select * from Doctors,Sections,BigSections,DoctorType "+
      "where Doctors.SectionID = Sections.SectionID and BigSections.BigSectionID = Sections.BigSectionID and "+
      "Doctors.DoctorTypeID=DoctorType.DoctorTypeID and DoctorType.DoctorTypeName='祖传医师' order by DoctorID";
   }
   this.dlDoctor.Dispose();
   try
   {
    DataSet dsDoctor = PubClass.DbOperate.ExecuteSqlDataAdapter(strSectionID);

    //使用页面内置的数据源PagedDataSource(具有翻页功能)
    PagedDataSource objPage = new PagedDataSource();
    objPage.DataSource = dsDoctor.Tables[0].DefaultView;
    objPage.AllowPaging =true;
    objPage.PageSize = 9;
    int curPage;
    if(Request.QueryString["Page"]!=null)
    {
     curPage = Int32.Parse(Request.QueryString["Page"].ToString()) ;
    }
    else
    {
     curPage = 1;
    }
    objPage.CurrentPageIndex = curPage -1;

   //lblCurPage为显示当前页的Lable控件
    lblCurPage.Text = "当前页: 第"+curPage.ToString()+"页";
    if(!objPage.IsFirstPage)
    {
     this.lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath+"?Page="+Convert.ToString(curPage-1);
    }
    if(!objPage.IsLastPage)
    {
     this.lnkNext.NavigateUrl = Request.CurrentExecutionFilePath+"?Page="+Convert.ToString(curPage+1);
    }
    
    this.dlDoctor.DataSource = objPage;
    this.dlDoctor.DataBind();   
   }  
   catch(Exception Err)
   {
    Response.Write(PubClass.CommonTool.PopShow(Err.Message));
   }
  }

------解决方案--------------------
翻页再一次邦定DataList1
------解决方案--------------------
点击下一页需要重新绑定数据
------解决方案--------------------
C# code

DataList翻页2008-01-09 14:27protected 
                         关于asp.net的Main()方法有关问题