Gridview直接与数据库连接了,在页面text里面输入内容,点击一个查询的按钮就可以把查询的内容显示在Gridview里面,谢谢高手!希望请教

解决方案 »

  1.   

    datatable.Select("xxx='" + xxxx + "'");
      

  2.   

    建议楼主完成地看完这个入门级的教程:
    http://www.cnblogs.com/eddie005/archive/2006/08/01/WorkingWithData_ASPNET2.html
      

  3.   

    protected void Button5_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text!= "" && TextBox2.Text == "")
            {
                TbYhxx_sqlstr = "select * from TbYhxx where Yhid='" + TextBox1.Text + "'";
            }
            else if (TextBox2.Text != "" && (TextBox1.Text == ""))
            {
                TbYhxx_sqlstr = "select * from TbYhxx where Dlip='" + TextBox2.Text + "'";
            }
            else if ((TextBox1.Text == "") && (TextBox2.Text == ""))
            {
                TbYhxx_sqlstr = "select * from TbYhxx where Yhid='" + TextBox1.Text + "'or Dlip='" + TextBox2.Text + "'";
            }
            else
            {
                TbYhxx_sqlstr = "select * from TbYhxx where Yhid='" + TextBox1.Text + "'or Dlip='" + TextBox2.Text + "'";
            }
          不知道这里怎么写与数据库连接的代码
                }
      

  4.   

    重新获得要查询的数据源,绑定给gridview就行了
      

  5.   

    在asp.net2.0里,大概不会再有人像楼上这样写代码...
      

  6.   

    public string getStrWhere()
        {
            string strWhere = "1=1";
            if (tb_Code.Text != string.Empty)
            {
                strWhere = strWhere + " And Code='" + tb_Code.Text + "'";
            }
            if (tb_Name.Text != string.Empty)
            {
                strWhere = strWhere + " And Name='" + tb_Name.Text + "'";
            }
            }...............bindData(...,...)
    {
     page.PageBindSearch(this.anp_WellGobPage, "表名", "主键", strwhere(条件), OrderFieldStr, gv_WellGob(gridview));
    }
      

  7.   

    private void GetBinder(string str)
    {
       sqlconnection con = new sqlconnection("连接数据库字符串");
       string sql="select * from table where 字段=str;
        sqldataAdapter adapter = new sqldataAdapter(sql,con);
       Dataset ds = new Dataset();
       adapter.fill(ds);
       this.gridview.datasource=ds.table[0];
       this.gridview.databind();
    }在button点击事件中调用这个方法
    把Textbox的值传入就可以了!
      

  8.   

    conn =new sqlconnection("");
    adp =new sqldatapater ("select * from table where 条件",conn)
    ds=new dataset();
    adp.fill(ds,"虚拟表名");
    datagird.datasorse=ds.table["虚拟表名"].DefaultView;
    datagird.databind();太基础了,多看书,多写。