我做的是查询功能,查询条件在一个panel1中,查询结果在panel2中,查询出的结果是用aspnetpager的URL分页。加载查询页面的时候,panel1显示出查询条件,panel2不显示,点击查询条件中的开始查询的时候panel1不显示,显示出panel2中的查询结果。我出现的错误是在没有把aspnetpager的UrlPaging设置成False时候能够正常显示panel1中的查询条件的,也能查询出结果。
我用了aspnetpager的UrlPaging设置成True时候,得到结果是直接显示查询记录,也就是panel2中的查询结果显示出来了,而panel1没有显示,而没有按照我们的要求先显示panel1中的查询条件。

解决方案 »

  1.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!this.IsPostBack)
    {
    this.BindToPage();
    }
    this.TotalRecordset();
    // 在此处放置用户代码以初始化页面
    }
    private void BindToPage()
    {
    this.djdq.Attributes.Add("onChange","proform()");

    SqlConnection con = DB.createCon();
    con.Open();
    SqlCommand cmd = new SqlCommand("select * from setsystem where Sort=2 order by place",con);
    SqlDataReader sdr = cmd.ExecuteReader();
    this.tdly.DataSource=sdr; this.tdly.DataTextField="setname";
    this.tdly.DataValueField="ID";
    this.tdly.DataBind();
    this.tdly.Items.Insert(0,new ListItem("部门选择",""));
    sdr.Close();
    }
    private void Button1_Click(object sender, System.EventArgs e)
    { this.TotalRecordset();
    this.BindToDataGrid();
    }
    private void TotalRecordset()
    {
    SqlConnection con = DB.createCon();
    con.Open(); string StrSql="select count(upteam.ID) from upteam,team,line where team.ID=upteam.djtd and line.ID=upteam.xlmc  ";
    if(this.tdly.SelectedItem!=null && this.tdly.SelectedValue.ToString()!="")
    {
    StrSql=StrSql+" and upteam.tdly='"+this.tdly.SelectedValue.ToString()+"'";
    }

    if(this.xlmc.SelectedItem!=null && this.xlmc.SelectedValue.ToString()!="")
    {
    StrSql=StrSql+" and upteam.xlmc='"+this.xlmc.SelectedValue.ToString()+"'";
    } SqlCommand cmd = new SqlCommand(StrSql,con);
    //必须判断总计有多少条数
    this.AspNetPager1.RecordCount=(int)cmd.ExecuteScalar();
    }
    private void BindToDataGrid()
    {
    this.Panel1.Visible=false;
    this.Panel2.Visible=true;
    this.DataGrid1.Visible=true;
    this.AspNetPager1.Visible=true;
    SqlConnection con = DB.createCon();
    SqlDataAdapter sda = new SqlDataAdapter();
    string StrSql="select team.teamname,line.linename,upteam.ID,upteam.course_code,upteam.crs,upteam.ets,upteam.pts from upteam,team,line where team.ID=upteam.djtd and line.ID=upteam.xlmc  ";
    if(this.tdly.SelectedItem!=null && this.tdly.SelectedValue.ToString()!="")
    {
    StrSql=StrSql+" and upteam.tdly='"+this.tdly.SelectedValue.ToString()+"'";
    }

    if(this.xlmc.SelectedItem!=null && this.xlmc.SelectedValue.ToString()!="")
    {
    StrSql=StrSql+" and upteam.xlmc='"+this.xlmc.SelectedValue.ToString()+"'";
    } StrSql=StrSql+" order by upteam.st_time desc,upteam.tdly"; sda.SelectCommand=new SqlCommand(StrSql,con);
    DataSet ds = new DataSet(); //这一部分必须加上的,重新填充数据
    sda.Fill(ds,this.AspNetPager1.PageSize*(this.AspNetPager1.CurrentPageIndex-1),this.AspNetPager1.PageSize,"upteam");  this.DataGrid1.DataKeyField="ID";
    this.DataGrid1.DataSource=ds.Tables["upteam"];
    this.DataGrid1.DataBind();

    } //这部分必须加上,事件相应
    protected void AspNetPager1_PageChanged(object src,EventArgs e)
    {
    this.BindToDataGrid();
    }
      

  2.   

    url分页的话
    不是使用DoPostBack方式的提交
    那么
    if(!this.IsPostBack)
    {
    this.BindToPage();
    }
    这里的ViewState不存在
    修改取消IsPostBack的判断
    直接
    this.BindToPage();
      

  3.   

    我也遇到这样的问题,UrlPaging=true时 刚开始查询出来的条件显示正确的,但是点击第二页或者其他页时 记录恢复成没有条件的记录了。