大家好,我现在有写好了同一个页面中包含查询和显示查询结果(GridView)的报表。
我想把这两部分分到两个页面来,第一个页面是多个条件查询的窗口,然后点击查询按钮,就跳转到第二个页面,在第二个页面的GridView中显示出查询结果,不知道怎么来写,请大家帮忙了,谢谢!

解决方案 »

  1.   

    或者将button 的 posturl属性改成你的第二个界面的url,好像可以的
    我记得button有这么个属性,可以指定不是当前页的提交页面。
      

  2.   

    最简单的就是把检索条件的参数传给第二个页面,第二个页面pageload的时候检索一下。
      

  3.   

    第一页:
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" PostBackUrl="~/WebForm2.aspx" Text="Button" />WebForm2.aspx.cs
    protected void Page_Load(object sender, EventArgs e)
    {
       Response.Write(Request["TextBox1"]);
    }在第一页的文本框内输入内容,按Button,第二页可以显示
      

  4.   

    我第一页有写了这个public void query_data()
            {……
              …… }        protected void Button1_Click(object sender, EventArgs e)
            {
                query_data();}现在我要改写,第二页显示出查询结果,我第二页可以直接用query_data()吗?或者别的该怎么用?
      

  5.   

    页面1:依你所说,是一个多条件查询条件,比如有一个TextBox1,一个DropDownList1。
    然后是一个提交查询条件的按钮Button1private void Button1_Click(object sender,EventArgs e)
    {
        Response.Redirect("page2.aspx?txt='"+TextBox1.Text.Trim()+"'&ddl='"+DropDownList1.SelectedValue+"'");
    }页面2:获取页面1中传递过来的值,然后根据这个值进行查询private void Page_Load(object sender,EventArgs e)
    {
        string txt=Request.QueryString["txt"].ToString();
        string ddl=Request.QueryString["ddl"].ToString();
        然后你根据得到的这两个值查询数据库,得到DataTable,然后将其赋给GridView的DataSource,再进行绑定
    }
      

  6.   


    在按钮的单击事件中获得输入的文本
    首先组装查询语句:
    如 输入的包括 name,sex,agestring sql="select * from student where 1=1 ";
    if(name!="" && name!=null)
    {
    sql+=" name like '%"+name+"%' ";
    }
    if(sex!="" && sex!=null)
    {
    sql+=" sex='"+sex+"'";
    }
    if(age>0)
    {
    sql+=" age>"+age;
    }上面组装查询语句,这也是解决这个问题的关键.其余的在就是查询数据库得到结果DataSet ,或者一个 集合
    按后与GridView绑定就行了GrivdView.DataSource=ds;
    GrivdView.DataBind();