当前位置: 代码迷 >> ASP.NET >> 急100分再问一个!IsPostBack翻页的有关问题
  详细解决方案

急100分再问一个!IsPostBack翻页的有关问题

热度:9266   发布时间:2013-02-25 00:00:00.0
急!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 System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection();protected System.Data.SqlClient.SqlCommand sqlCommand1 = new System.Data.SqlClient.SqlCommand();protected System.Data.SqlClient.SqlDataReader sqlDataReader1;protected System.Data.DataSet dataSet1;protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;private void Page_Load(object sender, System.EventArgs e){sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter("select * from db","Data Source=.; Initial Catalog=db;User id=sa; pwd=sa");     dataSet1 = new DataSet();     sqlDataAdapter1.Fill(dataSet1);       PagedDataSource pds = new PagedDataSource();     pds.DataSource = dataSet1.Tables[0].DefaultView;     pds.AllowPaging = true;     pds.PageSize = 10;     int CurPage1=1;          pds.CurrentPageIndex = CurPage1 - 1;     DIV1.InnerHtml = "当前页:第 " + CurPage1.ToString() + " 页 ,共 " + pds.PageCount + " 页";       if (!pds.IsFirstPage)     {      Prv.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage1 - 1);           Top.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";     }     if (!pds.IsLastPage)     {      Dow.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage1 + 1);           Bot.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + pds.PageCount;     }         DataList1.DataSource = pds;     DataList1.DataBind();}
  相关解决方案