我用的是Vs2005,想在当前页用条件模糊查询另一页,另一页是个gridview列表,把查询结果显示在另一页的gridview中,应该怎么弄?请给出全部代码,谢谢

解决方案 »

  1.   

    http://www.maxhost.cn/viewthread.php?tid=1742
      

  2.   

    把SQL存在session内可以吧,。
      

  3.   

    应该怎么弄呢,请教一下,我的代码如下,应该怎么改才可以
    protected void Button1_Click(object sender, EventArgs e)
        {
            string strConn = "Server=song;uid=sa;pwd=;Database=hs_px";
            SqlConnection conn = new SqlConnection(strConn);
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = cmd;
            DataSet ds = new DataSet();
            string strsql="select * from pxjl where 1=1";
            cmd.CommandText =strsql ;
            adapter.Fill(ds, "pxjl");
            GridView gv = new GridView();
            gv.DataSource = ds.Tables["pxjl"].DefaultView;
            gv.DataBind();
            if (Txtnf.Text != "")
            {
                strsql = strsql + "and nf like '%" + Txtnf.Text + "%'";
                Session["nf"] = Txtnf.Text;
            }
            Response.Redirect("lb.aspx?search");
            conn.Close();
        }
      

  4.   

    这里有什么错误呢,帮帮忙,怎么实现不了查询呢
    protected void Page_Load(object sender, EventArgs e)
        {        Txtnf.Text = Request.QueryString["nf"];
        }    protected void Button1_Click(object sender, EventArgs e)
        {
            string strConn = "Server=song;uid=sa;pwd=;Database=hs_px";
            SqlConnection conn = new SqlConnection(strConn);
            string strsql = "select * from pxjl";
            if (this.Txtnf.Text.Trim()!= "")
            {
                strsql = strsql+" where nf like '%" + this.Txtnf.Text.Trim() + "%'";
            }
    try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(strsql, conn);
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = cmd;
                DataSet ds = new DataSet();
                sda.Fill(ds,"pxjl");
                conn.Close();
                Response.Redirect("lb.aspx?search");
            }
            catch
            {
                Response.Write("<script language='JavaScript'>alert('查询失败!请稍后再试!');window.location='cx.aspx';</script>");
            }
            conn.Close();
        }